Skip to content

Commit

Permalink
Merge pull request #36 from OpenVoiceOS/release-1.2.0a1
Browse files Browse the repository at this point in the history
Release 1.2.0a1
  • Loading branch information
JarbasAl authored Jan 24, 2025
2 parents db79475 + 1e760fa commit 0bdccc0
Show file tree
Hide file tree
Showing 10 changed files with 234 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v1
with:
python-version: 3.8
python-version: "3.11"
- name: Install Build Tools
run: |
python -m pip install build wheel uv
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/install_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
max-parallel: 2
matrix:
python-version: [3.8, 3.9, "3.10" ]
python-version: [3.9, "3.10" ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/license_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v1
with:
python-version: 3.8
python-version: "3.11"
- name: Install Build Tools
run: |
python -m pip install build wheel uv
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish_stable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v1
with:
python-version: 3.8
python-version: "3.11"
- name: Install Build Tools
run: |
python -m pip install build wheel
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v1
with:
python-version: 3.8
python-version: "3.11"
- name: Install Build Tools
run: |
python -m pip install build wheel
Expand Down
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Changelog

## [1.1.1a1](https://github.com/OpenVoiceOS/ovos-padatious-pipeline-plugin/tree/1.1.1a1) (2024-12-11)
## [1.2.0a1](https://github.com/OpenVoiceOS/ovos-padatious-pipeline-plugin/tree/1.2.0a1) (2025-01-24)

[Full Changelog](https://github.com/OpenVoiceOS/ovos-padatious-pipeline-plugin/compare/1.1.0...1.1.1a1)
[Full Changelog](https://github.com/OpenVoiceOS/ovos-padatious-pipeline-plugin/compare/1.1.1...1.2.0a1)

**Merged pull requests:**

- performance: paralelize inference [\#32](https://github.com/OpenVoiceOS/ovos-padatious-pipeline-plugin/pull/32) ([JarbasAl](https://github.com/JarbasAl))
- feat: stemmer [\#35](https://github.com/OpenVoiceOS/ovos-padatious-pipeline-plugin/pull/35) ([JarbasAl](https://github.com/JarbasAl))



Expand Down
47 changes: 32 additions & 15 deletions ovos_padatious/intent_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,17 @@ class IntentContainer:
cache_dir (str): Directory for caching the neural network models and intent/entity files.
"""

def __init__(self, cache_dir: str) -> None:
def __init__(self, cache_dir: str, disable_padaos: bool = False) -> None:
os.makedirs(cache_dir, exist_ok=True)
self.cache_dir: str = cache_dir
self.must_train: bool = False
self.intents: IntentManager = IntentManager(cache_dir)
self.entities: EntityManager = EntityManager(cache_dir)
self.padaos: padaos.IntentContainer = padaos.IntentContainer()
self.disable_padaos = disable_padaos
if self.disable_padaos:
self.padaos = None
else:
self.padaos: padaos.IntentContainer = padaos.IntentContainer()
self.train_thread: Optional[Any] = None # deprecated
self.serialized_args: List[Dict[str, Any]] = [] # Serialized calls for training intents/entities

Expand All @@ -72,7 +76,10 @@ def clear(self) -> None:
self.must_train = False
self.intents = IntentManager(self.cache_dir)
self.entities = EntityManager(self.cache_dir)
self.padaos = padaos.IntentContainer()
if self.disable_padaos:
self.padaos = None
else:
self.padaos: padaos.IntentContainer = padaos.IntentContainer()
self.serialized_args = []

def instantiate_from_disk(self) -> None:
Expand Down Expand Up @@ -132,7 +139,8 @@ def add_intent(self, name: str, lines: List[str], reload_cache: bool = False, mu
must_train (bool): Whether the model needs training after adding the intent.
"""
self.intents.add(name, lines, reload_cache, must_train)
self.padaos.add_intent(name, lines)
if self.padaos is not None:
self.padaos.add_intent(name, lines)
self.must_train = must_train

@_save_args
Expand All @@ -156,7 +164,8 @@ def add_entity(self, name: str, lines: List[str], reload_cache: bool = False, mu
lines,
reload_cache,
must_train)
self.padaos.add_entity(name, lines)
if self.padaos is not None:
self.padaos.add_entity(name, lines)
self.must_train = must_train

@_save_args
Expand All @@ -172,8 +181,9 @@ def load_entity(self, name: str, file_name: str, reload_cache: bool = False, mus
"""
Entity.verify_name(name)
self.entities.load(Entity.wrap_name(name), file_name, reload_cache)
with open(file_name) as f:
self.padaos.add_entity(name, f.read().split('\n'))
if self.padaos is not None:
with open(file_name) as f:
self.padaos.add_entity(name, f.read().split('\n'))
self.must_train = must_train

@_save_args
Expand All @@ -193,8 +203,9 @@ def load_intent(self, name: str, file_name: str, reload_cache: bool = False, mus
must_train (bool): Whether the model needs training after loading the intent.
"""
self.intents.load(name, file_name, reload_cache)
with open(file_name) as f:
self.padaos.add_intent(name, f.read().split('\n'))
if self.padaos is not None:
with open(file_name) as f:
self.padaos.add_intent(name, f.read().split('\n'))
self.must_train = must_train

@_save_args
Expand All @@ -206,7 +217,8 @@ def remove_intent(self, name: str) -> None:
name (str): Name of the intent to remove.
"""
self.intents.remove(name)
self.padaos.remove_intent(name)
if self.padaos is not None:
self.padaos.remove_intent(name)
self.must_train = True

@_save_args
Expand All @@ -218,7 +230,8 @@ def remove_entity(self, name: str) -> None:
name (str): Name of the entity to remove.
"""
self.entities.remove(name)
self.padaos.remove_entity(name)
if self.padaos is not None:
self.padaos.remove_entity(name)

def train(self, debug: bool = True, force: bool = False, single_thread: Optional[bool] = None,
timeout: Optional[float] = None) -> bool:
Expand All @@ -241,7 +254,9 @@ def train(self, debug: bool = True, force: bool = False, single_thread: Optional
LOG.warning("'timeout' argument is deprecated and will be ignored")
if not self.must_train and not force:
return True
self.padaos.compile()

if self.padaos is not None:
self.padaos.compile()

# Train intents and entities
self.intents.train(debug=debug)
Expand All @@ -267,9 +282,11 @@ def calc_intents(self, query: str) -> List[MatchData]:
self.train()
intents = {i.name: i for i in self.intents.calc_intents(query, self.entities)}
sent = tokenize(query)
for perfect_match in self.padaos.calc_intents(query):
name = perfect_match['name']
intents[name] = MatchData(name, sent, matches=perfect_match['entities'], conf=1.0)

if self.padaos is not None:
for perfect_match in self.padaos.calc_intents(query):
name = perfect_match['name']
intents[name] = MatchData(name, sent, matches=perfect_match['entities'], conf=1.0)
return list(intents.values())

def calc_intent(self, query: str) -> MatchData:
Expand Down
Loading

0 comments on commit 0bdccc0

Please sign in to comment.