kevinkrahn commited on
Commit
7c4bf45
1 Parent(s): 7656737

Fix example code for huggingface transformers usage

Browse files
Files changed (1) hide show
  1. README.md +5 -4
README.md CHANGED
@@ -44,7 +44,7 @@ from transformers import AutoTokenizer, AutoModel
44
  import torch
45
 
46
 
47
- def cls_pooling(model_output, attention_mask):
48
  return model_output[0][:,0]
49
 
50
 
@@ -52,8 +52,8 @@ def cls_pooling(model_output, attention_mask):
52
  sentences = ['This is an example sentence', 'Each sentence is converted']
53
 
54
  # Load model from HuggingFace Hub
55
- tokenizer = AutoTokenizer.from_pretrained('kevinkrahn/shlm-grc-en')
56
- model = AutoModel.from_pretrained('kevinkrahn/shlm-grc-en')
57
 
58
  # Tokenize sentences
59
  encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
@@ -63,10 +63,11 @@ with torch.no_grad():
63
  model_output = model(**encoded_input)
64
 
65
  # Perform pooling. In this case, cls pooling.
66
- sentence_embeddings = cls_pooling(model_output, encoded_input['attention_mask'])
67
 
68
  print("Sentence embeddings:")
69
  print(sentence_embeddings)
 
70
  ```
71
 
72
  ## Citing & Authors
 
44
  import torch
45
 
46
 
47
+ def cls_pooling(model_output):
48
  return model_output[0][:,0]
49
 
50
 
 
52
  sentences = ['This is an example sentence', 'Each sentence is converted']
53
 
54
  # Load model from HuggingFace Hub
55
+ model = AutoModel.from_pretrained('kevinkrahn/shlm-grc-en', trust_remote_code=True)
56
+ tokenizer = AutoTokenizer.from_pretrained('kevinkrahn/shlm-grc-en', trust_remote_code=True)
57
 
58
  # Tokenize sentences
59
  encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
 
63
  model_output = model(**encoded_input)
64
 
65
  # Perform pooling. In this case, cls pooling.
66
+ sentence_embeddings = cls_pooling(model_output)
67
 
68
  print("Sentence embeddings:")
69
  print(sentence_embeddings)
70
+
71
  ```
72
 
73
  ## Citing & Authors