shubh2014shiv commited on
Commit
06bef3c
1 Parent(s): 69e47d1

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +49 -0
README.md ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Steps to use this model
2
+ This model uses tokenizer 'rinna/japanese-roberta-base'. Therefore, below steps are critical to run the model correctly.
3
+
4
+ 1. Create a local root directory on your system and new python environment.
5
+ 2. Install below requirements
6
+
7
+ ```
8
+ transformers==4.12.2
9
+ torch==1.10.0
10
+ numpy==1.21.3
11
+ pandas==1.3.4
12
+ sentencepiece==0.1.96
13
+ ```
14
+ 3. Go to link: "https://huggingface.co/spaces/shubh2014shiv/Japanese_NLP/tree/main" and download the fine tuned weights "reviewSentiments_jp.pt" in same local root directory.
15
+ 4. Rename the downloaded weights as "reviewSentiments_jp.pt"
16
+ 5. Use below code in the newly created environment.
17
+
18
+ ```
19
+ from transformers import T5Tokenizer,BertForSequenceClassification
20
+ import torch
21
+ tokenizer = T5Tokenizer.from_pretrained('rinna/japanese-roberta-base')
22
+ japanese_review_text = "履きやすい。タイムセールで購入しました。見た目以上にカッコいいです。(^^)"
23
+ encoded_data = tokenizer.batch_encode_plus([japanese_review_text ],
24
+ add_special_tokens=True,
25
+ return_attention_mask=True,
26
+ padding=True,
27
+ max_length=200,
28
+ return_tensors='pt',
29
+ truncation=True)
30
+ input_ids = encoded_data['input_ids']
31
+ attention_masks = encoded_data['attention_mask']
32
+ model = BertForSequenceClassification.from_pretrained("shubh2014shiv/jp_review_sentiments_amzn",
33
+ num_labels=2,
34
+ output_attentions=False,
35
+ output_hidden_states=False)
36
+ model.load_state_dict(torch.load('reviewSentiments_jp.pt',map_location=torch.device('cpu')))
37
+ inputs = { 'input_ids': input_ids,
38
+ 'attention_mask': attention_masks}
39
+ with torch.no_grad():
40
+ outputs = model(**inputs)
41
+
42
+ logits = outputs.logits
43
+ logits = logits.detach().cpu().numpy()
44
+ scores = 1 / (1 + np.exp(-1 * logits))
45
+ result = {"TEXT (文章)": jp_review_text,'NEGATIVE (ネガティブ)': scores[0][0], 'POSITIVE (ポジティブ)': scores[0][1]}
46
+ ```
47
+
48
+ Output should be as below:
49
+ {'TEXT (文章)': '履きやすい。タイムセールで購入しました。見た目以上にカッコいいです。(^^)', 'NEGATIVE (ネガティブ)': 0.023672901, 'POSITIVE (ポジティブ)': 0.96819043}