Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CV2-5122 add paraphrase multilingual #109

Merged
merged 2 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified lib/model/__pycache__/fptg.cpython-39.pyc
Binary file not shown.
Binary file modified lib/model/__pycache__/indian_sbert.cpython-39.pyc
Binary file not shown.
9 changes: 9 additions & 0 deletions lib/model/paraphrase_multilingual.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from lib.model.generic_transformer import GenericTransformerModel
MODEL_NAME = 'sentence-transformers/paraphrase-multilingual-mpnet-base-v2'
class Model(GenericTransformerModel):
BATCH_SIZE = 100
def __init__(self):
"""
Init ParaphraseMultilingual model. Fairly standard for all vectorizers.
"""
super().__init__(MODEL_NAME)
2 changes: 1 addition & 1 deletion test/lib/model/test_indian_sbert.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ def test_respond(self):
self.assertEqual(response[0].body.result, [1, 2, 3])

if __name__ == '__main__':
unittest.main()
unittest.main()
32 changes: 32 additions & 0 deletions test/lib/model/test_paraphrase_multilingual.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import os
computermacgyver marked this conversation as resolved.
Show resolved Hide resolved
import unittest
from unittest.mock import MagicMock

import numpy as np

from lib.model.generic_transformer import GenericTransformerModel
from lib import schemas

class TestParaphraseMultilingual(unittest.TestCase):
def setUp(self):
self.model = GenericTransformerModel(None)
self.mock_model = MagicMock()

def test_vectorize(self):
texts = [schemas.parse_message({"body": {"id": "123", "callback_url": "http://example.com/callback", "text": "Hello, how are you?"}, "model_name": "paraphrase_multilingual__Model"}), schemas.parse_message({"body": {"id": "123", "callback_url": "http://example.com/callback", "text": "I'm doing great, thanks!"}, "model_name": "paraphrase_multilingual__Model"})]
self.model.model = self.mock_model
self.model.model.encode = MagicMock(return_value=np.array([[4, 5, 6], [7, 8, 9]]))
vectors = self.model.vectorize(texts)
self.assertEqual(len(vectors), 2)
self.assertEqual(vectors[0], [4, 5, 6])
self.assertEqual(vectors[1], [7, 8, 9])

def test_respond(self):
query = schemas.parse_message({"body": {"id": "123", "callback_url": "http://example.com/callback", "text": "What is the capital of India?"}, "model_name": "paraphrase_multilingual__Model"})
self.model.vectorize = MagicMock(return_value=[[1, 2, 3]])
response = self.model.respond(query)
self.assertEqual(len(response), 1)
self.assertEqual(response[0].body.result, [1, 2, 3])

if __name__ == '__main__':
unittest.main()
Loading