misc

sentence_transformers.util.misc.disable_datasets_caching()[source]

A context manager that will disable caching in the datasets library.

sentence_transformers.util.misc.disable_logging(highest_level=50)[source]

A context manager that will prevent any logging messages triggered during the body from being processed.

Parameters:

highest_level – the maximum logging level allowed.

sentence_transformers.util.misc.fullname(obj) str[source]

Gives a full name (package_name.class_name) for a class / object in Python. Will be used to load the correct classes from JSON files

Parameters:

obj – The object for which to get the full name, e.g. an instance of a class or the class itself.

Returns:

The full name of the object.

Return type:

str

Example

>>> from sentence_transformers.sentence_transformer.losses import MultipleNegativesRankingLoss
>>> from sentence_transformers import SentenceTransformer
>>> from sentence_transformers.util import fullname
>>> model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')
>>> loss = MultipleNegativesRankingLoss(model)
>>> fullname(loss)
'sentence_transformers.sentence_transformer.losses.multiple_negatives_ranking.MultipleNegativesRankingLoss'
sentence_transformers.util.misc.import_from_string(dotted_path: str) type[source]

Import a dotted module path and return the attribute/class designated by the last name in the path. Raise ImportError if the import failed.

Parameters:

dotted_path (str) – The dotted module path.

Returns:

The attribute/class designated by the last name in the path.

Return type:

Any

Raises:

ImportError – If the import failed.

Example

>>> import_from_string('sentence_transformers.sentence_transformer.losses.multiple_negatives_ranking.MultipleNegativesRankingLoss')
<class 'sentence_transformers.sentence_transformer.losses.multiple_negatives_ranking.MultipleNegativesRankingLoss'>