Update README.md
Browse files
README.md
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
---
|
| 2 |
-
|
| 3 |
language_creators:
|
| 4 |
- unknown
|
| 5 |
language:
|
|
@@ -16,9 +15,9 @@ task_categories:
|
|
| 16 |
- unknown
|
| 17 |
task_ids:
|
| 18 |
- unknown
|
|
|
|
|
|
|
| 19 |
---
|
| 20 |
-
|
| 21 |
-
|
| 22 |
#### Table of contents
|
| 23 |
1. [Introduction](#introduction)
|
| 24 |
2. [Main results](#results)
|
|
@@ -58,7 +57,6 @@ git clone git@github.com:ViralLab/TurkishBERTweet.git
|
|
| 58 |
cd TurkishBERTweet
|
| 59 |
python -m venv venv
|
| 60 |
source venv/bin/activate
|
| 61 |
-
|
| 62 |
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
|
| 63 |
pip install peft
|
| 64 |
pip install transformers
|
|
@@ -68,10 +66,8 @@ pip install transformers
|
|
| 68 |
## <a name="preprocess"></a> Twitter Preprocessor
|
| 69 |
```python
|
| 70 |
from Preprocessor import preprocess
|
| 71 |
-
|
| 72 |
text = """Lab'ımıza "viral" adını verdik çünkü amacımız disiplinler arası sınırları aşmak ve aralarında yeni bağlantılar kurmak! 🔬 #ViralLab
|
| 73 |
https://varollab.com/"""
|
| 74 |
-
|
| 75 |
preprocessed_text = preprocess(text)
|
| 76 |
print(preprocessed_text)
|
| 77 |
```
|
|
@@ -87,15 +83,11 @@ lab'ımıza "viral" adını verdik çünkü amacımız disiplinler arası sını
|
|
| 87 |
import torch
|
| 88 |
from transformers import AutoTokenizer, AutoModel
|
| 89 |
from Preprocessor import preprocess
|
| 90 |
-
|
| 91 |
tokenizer = AutoTokenizer.from_pretrained("VRLLab/TurkishBERTweet")
|
| 92 |
turkishBERTweet = AutoModel.from_pretrained("VRLLab/TurkishBERTweet")
|
| 93 |
-
|
| 94 |
text = """Lab'ımıza "viral" adını verdik çünkü amacımız disiplinler arası sınırları aşmak ve aralarında yeni bağlantılar kurmak! 💥🔬 #ViralLab #DisiplinlerArası #YenilikçiBağlantılar"""
|
| 95 |
-
|
| 96 |
preprocessed_text = preprocess(text)
|
| 97 |
input_ids = torch.tensor([tokenizer.encode(preprocessed_text)])
|
| 98 |
-
|
| 99 |
with torch.no_grad():
|
| 100 |
features = turkishBERTweet(input_ids) # Models outputs are now tuples
|
| 101 |
```
|
|
@@ -109,16 +101,13 @@ from peft import (
|
|
| 109 |
PeftModel,
|
| 110 |
PeftConfig,
|
| 111 |
)
|
| 112 |
-
|
| 113 |
from transformers import (
|
| 114 |
AutoModelForSequenceClassification,
|
| 115 |
AutoTokenizer)
|
| 116 |
from Preprocessor import preprocess
|
| 117 |
|
| 118 |
-
|
| 119 |
peft_model = "VRLLab/TurkishBERTweet-Lora-SA"
|
| 120 |
peft_config = PeftConfig.from_pretrained(peft_model)
|
| 121 |
-
|
| 122 |
# loading Tokenizer
|
| 123 |
padding_side = "right"
|
| 124 |
tokenizer = AutoTokenizer.from_pretrained(
|
|
@@ -126,21 +115,17 @@ tokenizer = AutoTokenizer.from_pretrained(
|
|
| 126 |
)
|
| 127 |
if getattr(tokenizer, "pad_token_id") is None:
|
| 128 |
tokenizer.pad_token_id = tokenizer.eos_token_id
|
| 129 |
-
|
| 130 |
id2label_sa = {0: "negative", 2: "positive", 1: "neutral"}
|
| 131 |
turkishBERTweet_sa = AutoModelForSequenceClassification.from_pretrained(
|
| 132 |
peft_config.base_model_name_or_path, return_dict=True, num_labels=len(id2label_sa), id2label=id2label_sa
|
| 133 |
)
|
| 134 |
turkishBERTweet_sa = PeftModel.from_pretrained(turkishBERTweet_sa, peft_model)
|
| 135 |
-
|
| 136 |
sample_texts = [
|
| 137 |
"Viral lab da insanlar hep birlikte çalışıyorlar. hepbirlikte çalışan insanlar birbirlerine yakın oluyorlar.",
|
| 138 |
"americanin diplatlari turkiyeye gelmesin 😤",
|
| 139 |
"Mark Zuckerberg ve Elon Musk'un boks müsabakası süper olacak! 🥷",
|
| 140 |
"Adam dun ne yediğini unuttu"
|
| 141 |
]
|
| 142 |
-
|
| 143 |
-
|
| 144 |
preprocessed_texts = [preprocess(s) for s in sample_texts]
|
| 145 |
with torch.no_grad():
|
| 146 |
for s in preprocessed_texts:
|
|
@@ -161,16 +146,13 @@ from peft import (
|
|
| 161 |
PeftModel,
|
| 162 |
PeftConfig,
|
| 163 |
)
|
| 164 |
-
|
| 165 |
from transformers import (
|
| 166 |
AutoModelForSequenceClassification,
|
| 167 |
AutoTokenizer)
|
| 168 |
from Preprocessor import preprocess
|
| 169 |
|
| 170 |
-
|
| 171 |
peft_model = "VRLLab/TurkishBERTweet-Lora-HS"
|
| 172 |
peft_config = PeftConfig.from_pretrained(peft_model)
|
| 173 |
-
|
| 174 |
# loading Tokenizer
|
| 175 |
padding_side = "right"
|
| 176 |
tokenizer = AutoTokenizer.from_pretrained(
|
|
@@ -178,32 +160,26 @@ tokenizer = AutoTokenizer.from_pretrained(
|
|
| 178 |
)
|
| 179 |
if getattr(tokenizer, "pad_token_id") is None:
|
| 180 |
tokenizer.pad_token_id = tokenizer.eos_token_id
|
| 181 |
-
|
| 182 |
id2label_hs = {0: "No", 1: "Yes"}
|
| 183 |
turkishBERTweet_hs = AutoModelForSequenceClassification.from_pretrained(
|
| 184 |
peft_config.base_model_name_or_path, return_dict=True, num_labels=len(id2label_hs), id2label=id2label_hs
|
| 185 |
)
|
| 186 |
turkishBERTweet_hs = PeftModel.from_pretrained(turkishBERTweet_hs, peft_model)
|
| 187 |
-
|
| 188 |
-
|
| 189 |
sample_texts = [
|
| 190 |
"Viral lab da insanlar hep birlikte çalışıyorlar. hepbirlikte çalışan insanlar birbirlerine yakın oluyorlar.",
|
| 191 |
"kasmayin artik ya kac kere tanik olduk bu azgin tehlikeli \u201cmultecilerin\u201d yaptiklarina? bir afgan taragindan kafasi tasla ezilip tecavuz edilen kiza da git boyle cihangir solculugu yap yerse?",
|
| 192 |
]
|
| 193 |
-
|
| 194 |
-
|
| 195 |
preprocessed_texts = [preprocess(s) for s in sample_texts]
|
| 196 |
with torch.no_grad():
|
| 197 |
for s in preprocessed_texts:
|
| 198 |
ids = tokenizer.encode_plus(s, return_tensors="pt")
|
| 199 |
-
label_id =
|
| 200 |
print(id2label_hs[label_id],":", s)
|
| 201 |
```
|
| 202 |
|
| 203 |
```output
|
| 204 |
No : viral lab da insanlar hep birlikte çalışıyorlar. hepbirlikte çalışan insanlar birbirlerine yakın oluyorlar.
|
| 205 |
Yes : kasmayin artik ya kac kere tanik olduk bu azgin tehlikeli “multecilerin” yaptiklarina? bir afgan taragindan kafasi tasla ezilip tecavuz edilen kiza da git boyle cihangir solculugu yap yerse?
|
| 206 |
-
|
| 207 |
```
|
| 208 |
|
| 209 |
|
|
@@ -221,3 +197,4 @@ Yes : kasmayin artik ya kac kere tanik olduk bu azgin tehlikeli ��multecilerin
|
|
| 221 |
## Acknowledgments
|
| 222 |
We thank [Fatih Amasyali](https://avesis.yildiz.edu.tr/amasyali) for providing access to Tweet Sentiment datasets from Kemik group.
|
| 223 |
This material is based upon work supported by the Google Cloud Research Credits program with the award GCP19980904. We also thank TUBITAK (121C220 and 222N311) for funding this project.
|
|
|
|
|
|
| 1 |
---
|
|
|
|
| 2 |
language_creators:
|
| 3 |
- unknown
|
| 4 |
language:
|
|
|
|
| 15 |
- unknown
|
| 16 |
task_ids:
|
| 17 |
- unknown
|
| 18 |
+
widget:
|
| 19 |
+
- text: "bugün <mask> hissediyorum"
|
| 20 |
---
|
|
|
|
|
|
|
| 21 |
#### Table of contents
|
| 22 |
1. [Introduction](#introduction)
|
| 23 |
2. [Main results](#results)
|
|
|
|
| 57 |
cd TurkishBERTweet
|
| 58 |
python -m venv venv
|
| 59 |
source venv/bin/activate
|
|
|
|
| 60 |
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
|
| 61 |
pip install peft
|
| 62 |
pip install transformers
|
|
|
|
| 66 |
## <a name="preprocess"></a> Twitter Preprocessor
|
| 67 |
```python
|
| 68 |
from Preprocessor import preprocess
|
|
|
|
| 69 |
text = """Lab'ımıza "viral" adını verdik çünkü amacımız disiplinler arası sınırları aşmak ve aralarında yeni bağlantılar kurmak! 🔬 #ViralLab
|
| 70 |
https://varollab.com/"""
|
|
|
|
| 71 |
preprocessed_text = preprocess(text)
|
| 72 |
print(preprocessed_text)
|
| 73 |
```
|
|
|
|
| 83 |
import torch
|
| 84 |
from transformers import AutoTokenizer, AutoModel
|
| 85 |
from Preprocessor import preprocess
|
|
|
|
| 86 |
tokenizer = AutoTokenizer.from_pretrained("VRLLab/TurkishBERTweet")
|
| 87 |
turkishBERTweet = AutoModel.from_pretrained("VRLLab/TurkishBERTweet")
|
|
|
|
| 88 |
text = """Lab'ımıza "viral" adını verdik çünkü amacımız disiplinler arası sınırları aşmak ve aralarında yeni bağlantılar kurmak! 💥🔬 #ViralLab #DisiplinlerArası #YenilikçiBağlantılar"""
|
|
|
|
| 89 |
preprocessed_text = preprocess(text)
|
| 90 |
input_ids = torch.tensor([tokenizer.encode(preprocessed_text)])
|
|
|
|
| 91 |
with torch.no_grad():
|
| 92 |
features = turkishBERTweet(input_ids) # Models outputs are now tuples
|
| 93 |
```
|
|
|
|
| 101 |
PeftModel,
|
| 102 |
PeftConfig,
|
| 103 |
)
|
|
|
|
| 104 |
from transformers import (
|
| 105 |
AutoModelForSequenceClassification,
|
| 106 |
AutoTokenizer)
|
| 107 |
from Preprocessor import preprocess
|
| 108 |
|
|
|
|
| 109 |
peft_model = "VRLLab/TurkishBERTweet-Lora-SA"
|
| 110 |
peft_config = PeftConfig.from_pretrained(peft_model)
|
|
|
|
| 111 |
# loading Tokenizer
|
| 112 |
padding_side = "right"
|
| 113 |
tokenizer = AutoTokenizer.from_pretrained(
|
|
|
|
| 115 |
)
|
| 116 |
if getattr(tokenizer, "pad_token_id") is None:
|
| 117 |
tokenizer.pad_token_id = tokenizer.eos_token_id
|
|
|
|
| 118 |
id2label_sa = {0: "negative", 2: "positive", 1: "neutral"}
|
| 119 |
turkishBERTweet_sa = AutoModelForSequenceClassification.from_pretrained(
|
| 120 |
peft_config.base_model_name_or_path, return_dict=True, num_labels=len(id2label_sa), id2label=id2label_sa
|
| 121 |
)
|
| 122 |
turkishBERTweet_sa = PeftModel.from_pretrained(turkishBERTweet_sa, peft_model)
|
|
|
|
| 123 |
sample_texts = [
|
| 124 |
"Viral lab da insanlar hep birlikte çalışıyorlar. hepbirlikte çalışan insanlar birbirlerine yakın oluyorlar.",
|
| 125 |
"americanin diplatlari turkiyeye gelmesin 😤",
|
| 126 |
"Mark Zuckerberg ve Elon Musk'un boks müsabakası süper olacak! 🥷",
|
| 127 |
"Adam dun ne yediğini unuttu"
|
| 128 |
]
|
|
|
|
|
|
|
| 129 |
preprocessed_texts = [preprocess(s) for s in sample_texts]
|
| 130 |
with torch.no_grad():
|
| 131 |
for s in preprocessed_texts:
|
|
|
|
| 146 |
PeftModel,
|
| 147 |
PeftConfig,
|
| 148 |
)
|
|
|
|
| 149 |
from transformers import (
|
| 150 |
AutoModelForSequenceClassification,
|
| 151 |
AutoTokenizer)
|
| 152 |
from Preprocessor import preprocess
|
| 153 |
|
|
|
|
| 154 |
peft_model = "VRLLab/TurkishBERTweet-Lora-HS"
|
| 155 |
peft_config = PeftConfig.from_pretrained(peft_model)
|
|
|
|
| 156 |
# loading Tokenizer
|
| 157 |
padding_side = "right"
|
| 158 |
tokenizer = AutoTokenizer.from_pretrained(
|
|
|
|
| 160 |
)
|
| 161 |
if getattr(tokenizer, "pad_token_id") is None:
|
| 162 |
tokenizer.pad_token_id = tokenizer.eos_token_id
|
|
|
|
| 163 |
id2label_hs = {0: "No", 1: "Yes"}
|
| 164 |
turkishBERTweet_hs = AutoModelForSequenceClassification.from_pretrained(
|
| 165 |
peft_config.base_model_name_or_path, return_dict=True, num_labels=len(id2label_hs), id2label=id2label_hs
|
| 166 |
)
|
| 167 |
turkishBERTweet_hs = PeftModel.from_pretrained(turkishBERTweet_hs, peft_model)
|
|
|
|
|
|
|
| 168 |
sample_texts = [
|
| 169 |
"Viral lab da insanlar hep birlikte çalışıyorlar. hepbirlikte çalışan insanlar birbirlerine yakın oluyorlar.",
|
| 170 |
"kasmayin artik ya kac kere tanik olduk bu azgin tehlikeli \u201cmultecilerin\u201d yaptiklarina? bir afgan taragindan kafasi tasla ezilip tecavuz edilen kiza da git boyle cihangir solculugu yap yerse?",
|
| 171 |
]
|
|
|
|
|
|
|
| 172 |
preprocessed_texts = [preprocess(s) for s in sample_texts]
|
| 173 |
with torch.no_grad():
|
| 174 |
for s in preprocessed_texts:
|
| 175 |
ids = tokenizer.encode_plus(s, return_tensors="pt")
|
| 176 |
+
label_id = turkishBERTweet_hs(**ids).logits.argmax(-1).item()
|
| 177 |
print(id2label_hs[label_id],":", s)
|
| 178 |
```
|
| 179 |
|
| 180 |
```output
|
| 181 |
No : viral lab da insanlar hep birlikte çalışıyorlar. hepbirlikte çalışan insanlar birbirlerine yakın oluyorlar.
|
| 182 |
Yes : kasmayin artik ya kac kere tanik olduk bu azgin tehlikeli “multecilerin” yaptiklarina? bir afgan taragindan kafasi tasla ezilip tecavuz edilen kiza da git boyle cihangir solculugu yap yerse?
|
|
|
|
| 183 |
```
|
| 184 |
|
| 185 |
|
|
|
|
| 197 |
## Acknowledgments
|
| 198 |
We thank [Fatih Amasyali](https://avesis.yildiz.edu.tr/amasyali) for providing access to Tweet Sentiment datasets from Kemik group.
|
| 199 |
This material is based upon work supported by the Google Cloud Research Credits program with the award GCP19980904. We also thank TUBITAK (121C220 and 222N311) for funding this project.
|
| 200 |
+
|