paraphrase-multilingual-mpnet-base-v2
Comprehensive information on the functionality and api usage of the paraphrase-multilingual-mpnet-base-v2 model
API Reference: Embeddings API
Model Reference: paraphrase-multilingual-mpnet-base-v2
Paper: Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
This model is a teacher-student model: Teacher model is paraphrase-mpnet-base-v2, and Student model is xlm-roberta-base. It is designed to generate paraphrases and determine sentence similarities in multiple languages.
Layers | Embedding Dimension | Recommended Sequence Length |
---|---|---|
12 | 768 | 128 |
Suitable Score Functions
- cosine-similarity
Examples
Calculate Sentence similarities
Here is an example of how to calculate sentence similarities using the paraphrase-multilingual-mpnet-base-v2 model and cosine similarity as the scoring function.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
import requests from sklearn.metrics.pairwise import cosine_similarity headers = {'Content-Type': 'application/json', 'Authorization': 'Bearer {EMBAAS_API_KEY}'} science_sentences = [ "Parton energy loss in QCD matter", "The Chiral Phase Transition in Dissipative Dynamics" ] data = { 'texts': science_sentences, 'model': 'paraphrase-multilingual-mpnet-base-v2', } response = requests.post("https://api.embaas.io/v1/embeddings/", json=data, headers=headers) embeddings = response.json()["data"] similarities = cosine_similarity([embeddings[0]["embedding"]], [embeddings[1]["embedding"]]) print(similarities)
Information Retrieval
This is an example of using the paraphrase-multilingual-mpnet-base-v2 model for retrieving the most relevant document for a given query.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
import requests import numpy as np from sklearn.metrics.pairwise import cosine_similarity headers = {'Content-Type': 'application/json', 'Authorization': 'Bearer {EMBAAS_API_KEY}'} def get_embeddings(texts, model): data = {'texts': texts, 'model': model} response = requests.post("https://api.embaas.io/v1/embeddings/", json=data, headers=headers) embeddings = [entry['embedding'] for entry in response.json()['data']] return np.array(embeddings) query_text = "where is the food stored in a yam plant" corpus_texts = [ "Capitalism has been dominant in the Western world since the end of feudalism, but most feel[who?] that the term 'mixed economies' more precisely describes most contemporary economies, due to their containing both private-owned and state-owned enterprises. In capitalism, prices determine the demand-supply scale. For example, higher demand for certain goods and services lead to higher prices and lower demand for certain goods lead to lower prices.", "The disparate impact theory is especially controversial under the Fair Housing Act because the Act regulates many activities relating to housing, insurance, and mortgage loans—and some scholars have argued that the theory's use under the Fair Housing Act, combined with extensions of the Community Reinvestment Act, contributed to rise of sub-prime lending and the crash of the U.S. housing market and ensuing global economic recession", "Disparate impact in United States labor law refers to practices in employment, housing, and other areas that adversely affect one group of people of a protected characteristic more than another, even though rules applied by employers or landlords are formally neutral. Although the protected classes vary by statute, most federal civil rights laws protect based on race, color, religion, national origin, and sex as protected traits, and some laws include disability status and other traits as well." ] model_name = "paraphrase-multilingual-mpnet-base-v2" query_embeddings = get_embeddings([query_text], model_name) corpus_embeddings = get_embeddings(corpus_texts, model_name) similarities = cosine_similarity(query_embeddings, corpus_embeddings) retrieved_doc_id = np.argmax(similarities) print(corpus_texts[retrieved_doc_id])