speechbrain.utils.dictionaries moduleο
Dictionary utilities, e.g. synonym dictionaries.
- Authors
Sylvain de Langen 2024
Summaryο
Classes:
Loads sets of synonym words and lets you look up if two words are synonyms. |
Referenceο
- class speechbrain.utils.dictionaries.SynonymDictionary[source]ο
Bases:
object
Loads sets of synonym words and lets you look up if two words are synonyms.
This could, for instance, be used to check for equality in the case of two spellings of the same word when normalization might be unsuitable.
Synonyms are not considered to be transitive: If A is a synonym of B and B is a synonym of C, then A is NOT considered a synonym of C unless they are added in the same synonym set.
- static from_json_file(file) SynonymDictionary [source]ο
Parses an opened file as JSON, where the top level structure is a list of sets of synonyms (i.e. words that are all synonyms with each other), e.g.
[ ["hello", "hi"], ["say", "speak", "talk"] ]
.- Parameters:
file (file object) β File object that supports reading (e.g. an `open`ed file)
- Returns:
Synonym dictionary frm the parsed JSON file with all synonym sets added.
- Return type:
- static from_json_path(path) SynonymDictionary [source]ο
Opens a file and parses it as JSON, with otherwise the same semantics as
from_json_file()
, which uses an opened file.- Parameters:
path (str) β Path to the JSON file
- Returns:
Synonym dictionary frm the parsed JSON file with all synonym sets added.
- Return type:
- add_synonym_set(words: Iterable[str]) None [source]ο
Add a set of words that are all synonyms with each other.
- Parameters:
words (Iterable[str]) β List of words that should be defined as synonyms to each other
- __call__(a: str, b: str) bool [source]ο
Check for the equality or synonym equality of two words.
- Parameters:
- Returns:
Whether
a
andb
should be considered synonyms. Not transitive, see the main class documentation.- Return type: