User bio

Project manager at a company dedicated to healthcare management software and a developer by hobby. I've always enjoyed programming in any language.
I've been passionate about programming and computing since I was 8 years old.
Always looking to learn more every day.
I love teaching anyone who needs my help.
The mountains are my friend, and I really enjoy hiking.

Show all
Member since Feb 21, 2018
Pinned posts:
Replies:

Este mensaje de error me lo dá cuando reinicio el componente, porque se queda totalmente bloqueado. Esa linea es la que apunta a la llamada al método 

set vector = ##class(St.Vectorsearch.Vector).Embedding(request.StringValue)

Voy a probar.

Es curioso porque si lo ejecuto desde el termina, tarda un poco pero responde. En cambio si es invocado desde un BP, se queda pillado y da un error en el BP.

El código de invocación es el que he puesto en el mensaje.

Este es mi código

ClassMethod Embedding(Text) [ Language = python ]
{
   from transformers import AutoTokenizer, AutoModel
   import torch
   import torch.nn.functional as F
   #Mean Pooling - Take attention mask into account for correct averaging
   def mean_pooling(model_output, attention_mask):
       token_embeddings = model_output[0] #First element of model_output contains all token embeddings
       input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
       return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)

   # Sentences we want sentence embeddings for
   # sentences = ['This is an example sentence', 'Each sentence is converted']
   sentences = [Text]
   # Load model from HuggingFace Hub
   #; tokenizer = AutoTokenizer.from_pretrained('sentence-transformers/all-MiniLM-L6-v2')
   #; model = AutoModel.from_pretrained('sentence-transformers/all-MiniLM-L6-v2')
   
   # Load model from multilingual model
   tokenizer = AutoTokenizer.from_pretrained('sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2')
   model = AutoModel.from_pretrained('sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2')
   # Tokenize sentences
   encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
   # Compute token embeddings
   with torch.no_grad():
       model_output = model(**encoded_input)
   # Perform pooling
   sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
   # Normalize embeddings
   sentence_embeddings = F.normalize(sentence_embeddings, p=2, dim=1)
   #print(sentence_embeddings)
   return str(sentence_embeddings[0].tolist())
}
Open Exchange applications:
Certifications & Credly badges:
Followers:
Following: