rasa-pro 3.12.10__py3-none-any.whl → 3.12.11__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of rasa-pro might be problematic. Click here for more details.

rasa/keys ADDED
@@ -0,0 +1 @@
1
+ {"segment": "CcvVD1I68Nkkxrv93cIqv1twIwrwG8nz", "sentry": "a283f1fde04347b099c8d729109dd450@o251570"}
@@ -1,9 +1,11 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import logging
4
+ import shutil
4
5
  import typing
5
6
  from collections import OrderedDict
6
7
  from enum import Enum
8
+ from pathlib import Path
7
9
  from typing import Any, Callable, Dict, List, Optional, Text, Tuple, Type
8
10
 
9
11
  import numpy as np
@@ -43,6 +45,10 @@ if typing.TYPE_CHECKING:
43
45
 
44
46
  CONFIG_FEATURES = "features"
45
47
 
48
+ TAGGERS_DIR = "taggers"
49
+ CRFSUITE_MODEL_FILE_NAME = "model.crfsuite"
50
+ PLAIN_CRF_MODEL_FILE_NAME = "model.txt"
51
+
46
52
 
47
53
  class CRFToken:
48
54
  def __init__(
@@ -419,19 +425,11 @@ class CRFEntityExtractor(GraphComponent, EntityExtractorMixin):
419
425
  """Loads trained component (see parent class for full docstring)."""
420
426
  try:
421
427
  with model_storage.read_from(resource) as model_dir:
422
- dataset = rasa.shared.utils.io.read_json_file(
423
- model_dir / "crf_dataset.json"
424
- )
425
428
  crf_order = rasa.shared.utils.io.read_json_file(
426
429
  model_dir / "crf_order.json"
427
430
  )
428
431
 
429
- dataset = [
430
- [CRFToken.create_from_dict(token_data) for token_data in sub_list]
431
- for sub_list in dataset
432
- ]
433
-
434
- entity_taggers = cls.train_model(dataset, config, crf_order)
432
+ entity_taggers = cls._load_taggers(model_dir, config)
435
433
 
436
434
  entity_extractor = cls(config, model_storage, resource, entity_taggers)
437
435
  entity_extractor.crf_order = crf_order
@@ -443,19 +441,71 @@ class CRFEntityExtractor(GraphComponent, EntityExtractorMixin):
443
441
  )
444
442
  return cls(config, model_storage, resource)
445
443
 
444
+ @classmethod
445
+ def _load_taggers(
446
+ cls, model_dir: Path, config: Dict[Text, Any]
447
+ ) -> Dict[str, "CRF"]:
448
+ """
449
+ Load taggers from model directory that persists trained binary
450
+ `model.crfsuite` files.
451
+ """
452
+
453
+ import pycrfsuite
454
+ import sklearn_crfsuite
455
+
456
+ # Get tagger directories
457
+ taggers_base = model_dir / TAGGERS_DIR
458
+ if not taggers_base.exists():
459
+ return {}
460
+
461
+ taggers_dirs = [
462
+ directory for directory in taggers_base.iterdir() if directory.is_dir()
463
+ ]
464
+
465
+ entity_taggers: Dict[str, "CRF"] = {}
466
+
467
+ for tagger_dir in taggers_dirs:
468
+ # Instantiate sklearns CRF wrapper for the pycrfsuite's Tagger
469
+ entity_tagger = sklearn_crfsuite.CRF(
470
+ algorithm="lbfgs",
471
+ # coefficient for L1 penalty
472
+ c1=config["L1_c"],
473
+ # coefficient for L2 penalty
474
+ c2=config["L2_c"],
475
+ # stop earlier
476
+ max_iterations=config["max_iterations"],
477
+ # include transitions that are possible, but not observed
478
+ all_possible_transitions=True,
479
+ )
480
+
481
+ # Load pycrfsuite tagger from the persisted binary model.crfsuite file
482
+ entity_tagger._tagger = pycrfsuite.Tagger()
483
+ entity_tagger._tagger.open(str(tagger_dir / CRFSUITE_MODEL_FILE_NAME))
484
+
485
+ entity_taggers[tagger_dir.name] = entity_tagger
486
+
487
+ return entity_taggers
488
+
446
489
  def persist(self, dataset: List[List[CRFToken]]) -> None:
447
490
  """Persist this model into the passed directory."""
448
491
  with self._model_storage.write_to(self._resource) as model_dir:
449
- data_to_store = [
450
- [token.to_dict() for token in sub_list] for sub_list in dataset
451
- ]
452
-
453
- rasa.shared.utils.io.dump_obj_as_json_to_file(
454
- model_dir / "crf_dataset.json", data_to_store
455
- )
456
492
  rasa.shared.utils.io.dump_obj_as_json_to_file(
457
493
  model_dir / "crf_order.json", self.crf_order
458
494
  )
495
+ if self.entity_taggers is not None:
496
+ for tag_name, entity_tagger in self.entity_taggers.items():
497
+ # Create the directories for storing the CRF model
498
+ tagger_dir = model_dir / TAGGERS_DIR / tag_name
499
+ tagger_dir.mkdir(parents=True, exist_ok=True)
500
+ # Create a plain text version of the CRF model
501
+ entity_tagger.tagger_.dump(
502
+ str(tagger_dir / PLAIN_CRF_MODEL_FILE_NAME)
503
+ )
504
+ # Persist binary version of the model.crfsuite
505
+ shutil.copy2(
506
+ src=entity_tagger.modelfile.name,
507
+ dst=tagger_dir / CRFSUITE_MODEL_FILE_NAME,
508
+ )
459
509
 
460
510
  @classmethod
461
511
  def _crf_tokens_to_features(
rasa/version.py CHANGED
@@ -1,3 +1,3 @@
1
1
  # this file will automatically be changed,
2
2
  # do not add anything but the version number here!
3
- __version__ = "3.12.10"
3
+ __version__ = "3.12.11"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: rasa-pro
3
- Version: 3.12.10
3
+ Version: 3.12.11
4
4
  Summary: State-of-the-art open-core Conversational AI framework for Enterprises that natively leverages generative AI for effortless assistant development.
5
5
  Keywords: nlp,machine-learning,machine-learning-library,bot,bots,botkit,rasa conversational-agents,conversational-ai,chatbot,chatbot-framework,bot-framework
6
6
  Author: Rasa Technologies GmbH
@@ -532,6 +532,7 @@ rasa/graph_components/validators/default_recipe_validator.py,sha256=iOVoB7zVTKes
532
532
  rasa/graph_components/validators/finetuning_validator.py,sha256=VfCGytnweijKBG8bAqYp7zKZB2aRgi2ZI8R0eou5Ev4,12865
533
533
  rasa/hooks.py,sha256=5ZMrqNz323w56MMY6E8jeZ_YXgRqq8p-yi18S2XOmbo,4061
534
534
  rasa/jupyter.py,sha256=TCYVD4QPQIMmfA6ZwDUBOBTAECwCwbU2XOkosodLO9k,1782
535
+ rasa/keys,sha256=2Stg1fstgJ203cOoW1B2gGMY29fhEnjIfTVxKv_fqPo,101
535
536
  rasa/llm_fine_tuning/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
536
537
  rasa/llm_fine_tuning/annotation_module.py,sha256=6wBBjGwONVlikp79xAHp5g3rydEhPM6kP1bw1g-maYk,8578
537
538
  rasa/llm_fine_tuning/conversations.py,sha256=QZVaUsfXe5iIE830Bv-_3oo8luhGfHpirvubxzOoEvA,4116
@@ -582,7 +583,7 @@ rasa/nlu/emulators/luis.py,sha256=BaBluhzyHbELy2ji9zMIMYNbGklQEJqwGu-Z1zaRFS8,30
582
583
  rasa/nlu/emulators/no_emulator.py,sha256=x8VoSxRm4aec8Fk797ipy78KxyBcBjnQ08xesLhG0nI,335
583
584
  rasa/nlu/emulators/wit.py,sha256=6ltOc8S__UzesWPGI6-igxnkUa6ZKoNLhpZU7o2g4R4,1930
584
585
  rasa/nlu/extractors/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
585
- rasa/nlu/extractors/crf_entity_extractor.py,sha256=UT3lfVOLKWDSki5hGrrDxHq-zNjb6oquIgGQq0PoGsQ,27532
586
+ rasa/nlu/extractors/crf_entity_extractor.py,sha256=Cv2ObNSyGdi-f2tCY0tu28gY12bf5x9mi5d1ncg1m6o,29400
586
587
  rasa/nlu/extractors/duckling_entity_extractor.py,sha256=vDW9VgQRgIw8Lc3nYoNJFR58IwSeB0Mt_K1Tz8lg7XQ,7687
587
588
  rasa/nlu/extractors/entity_synonyms.py,sha256=9Ums__jzagpkpQbCj5MKr44tkaicaA2zj_4KFe2FgME,7149
588
589
  rasa/nlu/extractors/extractor.py,sha256=WDw2a8fSmsHeYflNpZwYwQ2o-ffwUIkWY2B7gSlfuAY,17539
@@ -821,9 +822,9 @@ rasa/utils/train_utils.py,sha256=ClJx-6x3-h3Vt6mskacgkcCUJTMXjFPe3zAcy_DfmaU,212
821
822
  rasa/utils/url_tools.py,sha256=dZ1HGkVdWTJB7zYEdwoDIrEuyX9HE5WsxKKFVsXBLE0,1218
822
823
  rasa/utils/yaml.py,sha256=KjbZq5C94ZP7Jdsw8bYYF7HASI6K4-C_kdHfrnPLpSI,2000
823
824
  rasa/validator.py,sha256=524VlFTYK0B3iXYveVD6BDC3K0j1QfpzJ9O-TAWczmc,83166
824
- rasa/version.py,sha256=F6TWQP94ECROLtXqlCrwu9xSrvxZDs3JVTp6gPLbxfE,118
825
- rasa_pro-3.12.10.dist-info/METADATA,sha256=3wU4IxYsMJruxuysovjfW1wt7IOsh0YELYX4uvwhDhY,10616
826
- rasa_pro-3.12.10.dist-info/NOTICE,sha256=7HlBoMHJY9CL2GlYSfTQ-PZsVmLmVkYmMiPlTjhuCqA,218
827
- rasa_pro-3.12.10.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
828
- rasa_pro-3.12.10.dist-info/entry_points.txt,sha256=ckJ2SfEyTPgBqj_I6vm_tqY9dZF_LAPJZA335Xp0Q9U,43
829
- rasa_pro-3.12.10.dist-info/RECORD,,
825
+ rasa/version.py,sha256=XvXtUVw5FDQnXtExrv4wXMnPazsNF9kg9UQ_UNtd3wQ,118
826
+ rasa_pro-3.12.11.dist-info/METADATA,sha256=RhI4sfwSLwWa59piZoOXxn9CJg1xHBD1T-FJ2jk0yJE,10616
827
+ rasa_pro-3.12.11.dist-info/NOTICE,sha256=7HlBoMHJY9CL2GlYSfTQ-PZsVmLmVkYmMiPlTjhuCqA,218
828
+ rasa_pro-3.12.11.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
829
+ rasa_pro-3.12.11.dist-info/entry_points.txt,sha256=ckJ2SfEyTPgBqj_I6vm_tqY9dZF_LAPJZA335Xp0Q9U,43
830
+ rasa_pro-3.12.11.dist-info/RECORD,,