<html> <head> <link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" /> <script defer src="https://pyscript.net/alpha/pyscript.js"></script> <py-env> </py-env> </head> <body> <py-script> from sentence_transformers import SentenceTransformer, util model = SentenceTransformer('all-MiniLM-L6-v2') # Two lists of sentences sentences1 = ['The cat sits outside', 'A man is playing guitar', 'The new movie is awesome'] sentences2 = ['The dog plays in the garden', 'A woman watches TV', 'The new movie is so great'] #Compute embedding for both lists model = SentenceTransformer('sentence-transformers/all-mpnet-base-v2') embeddings1 = model.encode(sentences1, convert_to_tensor=True) embeddings2 = model.encode(sentences2, convert_to_tensor=True) #Compute cosine-similarities cosine_scores = util.cos_sim(embeddings1, embeddings2) #Output the pairs with their score for i in range(len(sentences1)): print("{} \t\t {} \t\t Score: {:.4f}".format(sentences1[i], sentences2[i], cosine_scores[i][i])) print ("___________________________________________________") </py-script> </body> </html>tengo este error
JsException(PythonError: Traceback (última llamada más reciente): Archivo "/lib/python3.10/site-packages/_pyodide/_base.py", línea 429, en eval_code .run(globals, locales) Archivo "/lib/python3 .10/site-packages/_pyodide/_base.py", línea 300, en run coroutine = eval(self.code, globals, locals) File "", línea 1, en ModuleNotFoundError: Ningún módulo llamado 'sentence_transformers' )
sentence_transformers no es un módulo integrado en la biblioteca estándar de Python, por lo que debe instalarlo. De acuerdo con la documentación , lo hace agregando el nombre del paquete al elemento py-env :
<py-env> - sentence-transformers </py-env>Sin embargo, no parece que los transformadores de oraciones estén disponibles en pyodide en este momento. Puede abrir un PR o un problema para agregarlo.