LASER Language-Agnostic SEntence Representations Embeddings by Meta AI
LASER is a Python library developed by the Meta AI Research team and used for creating multilingual sentence embeddings for over 147 languages as of 2/25/2024 - List of supported languages at https://github.com/facebookresearch/flores/blob/main/flores200/README.md#languages-in-flores-200
Dependenciesβ
To use LaserEmbed with LangChain, install the laser_encoders
Python
package.
%pip install laser_encoders
Importsβ
from langchain_community.embeddings.laser import LaserEmbeddings
Instantiating Laserβ
Parametersβ
lang: Optional[str]
>If empty will default to using a multilingual LASER encoder model (called βlaser2β). You can find the list of supported languages and lang_codes here and here .
# Ex Instantiationz
embeddings = LaserEmbeddings(lang="eng_Latn")
Usageβ
Generating document embeddingsβ
document_embeddings = embeddings.embed_documents(
["This is a sentence", "This is some other sentence"]
)
Generating query embeddingsβ
query_embeddings = embeddings.embed_query("This is a query")