itdainb commited on
Commit
b458202
·
verified ·
1 Parent(s): e9f47d0

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +15 -5
README.md CHANGED
@@ -55,7 +55,7 @@ pipeline_tag: text-classification
55
  ```python
56
  from pyvi import ViTokenizer
57
 
58
- query = "UIT là gì?"
59
  sentences = [
60
  "Trường Đại học Công nghệ Thông tin có tên tiếng Anh là University of Information Technology (viết tắt là UIT) là thành viên của Đại học Quốc Gia TP.HCM.",
61
  "Trường Đại học Kinh tế – Luật (tiếng Anh: University of Economics and Law – UEL) là trường đại học đào tạo và nghiên cứu khối ngành kinh tế, kinh doanh và luật hàng đầu Việt Nam.",
@@ -67,25 +67,30 @@ tokenized_sentences = [ViTokenizer.tokenize(sent) for sent in sentences]
67
 
68
  tokenized_pairs = [[tokenized_query, sent] for sent in tokenized_sentences]
69
 
70
- model_id = 'itdainb/PhoRanker'
 
71
  ```
72
 
73
  ## Usage with sentence-transformers
74
 
75
  ```python
76
  from sentence_transformers import CrossEncoder
77
- model = CrossEncoder(model_id, max_length=256)
78
 
79
  # For fp16 usage
80
  model.model.half()
81
 
82
  scores = model.predict(tokenized_pairs)
 
 
 
83
  ```
84
 
85
  ## Usage with transformers
86
 
87
  ```python
88
  from transformers import AutoTokenizer, AutoModelForSequenceClassification
 
89
 
90
  model = AutoModelForSequenceClassification.from_pretrained(model_id)
91
  tokenizer = AutoTokenizer.from_pretrained(model_id)
@@ -95,13 +100,18 @@ model.half()
95
 
96
  features = tokenizer(tokenized_pairs, padding=True, truncation="longest_first", return_tensors="pt", max_length=256)
97
 
 
 
98
  model.eval()
99
  with torch.no_grad():
100
  model_predictions = model(**features, return_dict=True)
 
101
  logits = model_predictions.logits
 
 
102
 
103
- scores = [score[0] for score in logits]
104
- print(scores)
105
  ```
106
 
107
  ## Performance
 
55
  ```python
56
  from pyvi import ViTokenizer
57
 
58
+ query = "Trường UIT là gì?"
59
  sentences = [
60
  "Trường Đại học Công nghệ Thông tin có tên tiếng Anh là University of Information Technology (viết tắt là UIT) là thành viên của Đại học Quốc Gia TP.HCM.",
61
  "Trường Đại học Kinh tế – Luật (tiếng Anh: University of Economics and Law – UEL) là trường đại học đào tạo và nghiên cứu khối ngành kinh tế, kinh doanh và luật hàng đầu Việt Nam.",
 
67
 
68
  tokenized_pairs = [[tokenized_query, sent] for sent in tokenized_sentences]
69
 
70
+ MODEL_ID = 'itdainb/PhoRanker'
71
+ MAX_LENGTH = 256
72
  ```
73
 
74
  ## Usage with sentence-transformers
75
 
76
  ```python
77
  from sentence_transformers import CrossEncoder
78
+ model = CrossEncoder(MODEL_ID, max_length=MAX_LENGTH)
79
 
80
  # For fp16 usage
81
  model.model.half()
82
 
83
  scores = model.predict(tokenized_pairs)
84
+
85
+ # 0.982, 0.2444, 0.9253
86
+ print(scores)
87
  ```
88
 
89
  ## Usage with transformers
90
 
91
  ```python
92
  from transformers import AutoTokenizer, AutoModelForSequenceClassification
93
+ import torch
94
 
95
  model = AutoModelForSequenceClassification.from_pretrained(model_id)
96
  tokenizer = AutoTokenizer.from_pretrained(model_id)
 
100
 
101
  features = tokenizer(tokenized_pairs, padding=True, truncation="longest_first", return_tensors="pt", max_length=256)
102
 
103
+ activation_function = torch.nn.Sigmoid() if model.config.num_labels == 1 else torch.nn.Identity()
104
+
105
  model.eval()
106
  with torch.no_grad():
107
  model_predictions = model(**features, return_dict=True)
108
+
109
  logits = model_predictions.logits
110
+ logits = activation_function(logits)
111
+ scores = [logit[0] for logit in logits]
112
 
113
+ # 0.9819, 0.2444, 0.9253
114
+ print(scores)
115
  ```
116
 
117
  ## Performance