The base version of
e5-v2 finetunned on an annotated subset of
C4. This model provides generic embedding for sentiment analysis. Embeddings can be used out of the box or fine-tuned on specific datasets.
Below is an example to encode text and get embedding.
1import torch
2from transformers import AutoTokenizer, AutoModel
3
4
5model = AutoModel.from_pretrained("Numind/e5-base-sentiment_analysis")
6tokenizer = AutoTokenizer.from_pretrained("Numind/e5-base-sentiment_analysis")
7device = torch.device('cuda') if torch.cuda.is_available() else torch.device('cpu')
8model.to(device)
9
10size = 256
11text = "This movie is amazing"
12
13encoding = tokenizer(
14 text,
15 truncation=True,
16 padding='max_length',
17 max_length= size,
18)
19
20emb = model(
21 torch.reshape(torch.tensor(encoding.input_ids),(1,len(encoding.input_ids))).to(device),output_hidden_states=True
22).hidden_states[-1].cpu().detach()
23
24embText = torch.mean(emb,axis = 1)
25