Views
No views yet
@misc{yildirim2024finetuning,
title={Fine-tuning Transformer-based Encoder for Turkish Language Understanding Tasks},
author={Savas Yildirim},
year={2024},
eprint={2401.17396},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
@book{yildirim2021mastering,
title={Mastering Transformers: Build state-of-the-art models from scratch with advanced natural language processing techniques},
author={Yildirim, Savas and Asgari-Chenaghlu, Meysam},
year={2021},
publisher={Packt Publishing Ltd}
}| size | data |
|---|---|
| 8000 | dev.tsv |
| 8262 | test.tsv |
| 32000 | train.tsv |
| 48290 | total |
1export GLUE_DIR="./sst-2-newall"
2export TASK_NAME=SST-2
3
4python3 run_glue.py \
5 --model_type bert \
6 --model_name_or_path dbmdz/bert-base-turkish-uncased\
7 --task_name "SST-2" \
8 --do_train \
9 --do_eval \
10 --data_dir "./sst-2-newall" \
11 --max_seq_length 128 \
12 --per_gpu_train_batch_size 32 \
13 --learning_rate 2e-5 \
14 --num_train_epochs 3.0 \
15 --output_dir "./model"05/10/2020 17:00:43 - INFO - transformers.trainer - ***** Running Evaluation *****
05/10/2020 17:00:43 - INFO - transformers.trainer - Num examples = 7999
05/10/2020 17:00:43 - INFO - transformers.trainer - Batch size = 8
Evaluation: 100% 1000/1000 [00:34<00:00, 29.04it/s]
05/10/2020 17:01:17 - INFO - __main__ - ***** Eval results sst-2 *****
05/10/2020 17:01:17 - INFO - __main__ - acc = 0.9539942492811602
05/10/2020 17:01:17 - INFO - __main__ - loss = 0.16348013816401363
1from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
2
3model = AutoModelForSequenceClassification.from_pretrained("savasy/bert-base-turkish-sentiment-cased")
4tokenizer = AutoTokenizer.from_pretrained("savasy/bert-base-turkish-sentiment-cased")
5sa= pipeline("sentiment-analysis", tokenizer=tokenizer, model=model)
6
7p = sa("bu telefon modelleri çok kaliteli , her parçası çok özel bence")
8print(p)
9# [{'label': 'LABEL_1', 'score': 0.9871089}]
10print(p[0]['label'] == 'LABEL_1')
11# True
12
13p = sa("Film çok kötü ve çok sahteydi")
14print(p)
15# [{'label': 'LABEL_0', 'score': 0.9975505}]
16print(p[0]['label'] == 'LABEL_1')
17# Falsecomment1 ... \t label
comment2 ... \t label
...
1from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
2
3model = AutoModelForSequenceClassification.from_pretrained("savasy/bert-base-turkish-sentiment-cased")
4tokenizer = AutoTokenizer.from_pretrained("savasy/bert-base-turkish-sentiment-cased")
5sa = pipeline("sentiment-analysis", tokenizer=tokenizer, model=model)
6
7input_file = "/path/to/your/file/yourfile.tsv"
8
9i, crr = 0, 0
10for line in open(input_file):
11 lines = line.strip().split("\t")
12 if len(lines) == 2:
13
14 i = i + 1
15 if i%100 == 0:
16 print(i)
17
18 pred = sa(lines[0])
19 pred = pred[0]["label"].split("_")[1]
20
21 if pred == lines[1]:
22 crr = crr + 1
23
24print(crr, i, crr/i)