ozcangundes commited on
Commit
5262ac2
1 Parent(s): d4ad2ad

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +104 -0
README.md ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: turkish
3
+ datasets:
4
+ - MLSUM
5
+ pipeline_tag: summarization
6
+ license: MIT
7
+ ---
8
+
9
+ # mT5-small based Turkish Summarization System
10
+
11
+ [Google's Multilingual T5-small](https://github.com/google-research/multilingual-t5) is fine-tuned on [MLSUM Turkish news dataset](https://github.com/recitalAI/MLSUM) for **Summarization** downstream task by using Pytorch Lightning.⚡
12
+
13
+ mT5 small model has 300 million parameters and model size is about 1.2GB. Therefore, it takes significant amount of time to fine tune it. The model is trained with 10 epochs, 8 batch size and 10e-4 learning rate. It took almost 4 hours. The max news length is kept as 784 and max summary length is determined as 64.
14
+
15
+
16
+ **Important Note**: mT5 was only pre-trained on [mC4](https://www.tensorflow.org/datasets/catalog/c4#c4multilingual)
17
+ excluding any supervised training. Therefore, the mT5 model has to be fine-tuned before it is useable on a downstream task.
18
+
19
+ ## Dataset
20
+
21
+ MLSUM dataset has more than 250K Turkish news with their related summaries. Since the mT5 model size and vocabulary is so large, 20K data is used for training and 4K data is used for validation. For more information about the dataset, please read this [great paper](https://arxiv.org/abs/2004.14900).
22
+ ## Usage 🚀
23
+
24
+ ```python
25
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
26
+
27
+ tokenizer = AutoTokenizer.from_pretrained("ozcangundes/mt5-small-turkish-summarization")
28
+
29
+ model = AutoModelForSeq2SeqLM.from_pretrained("ozcangundes/mt5-small-turkish-summarization")
30
+
31
+ def generate_summary(main_news):
32
+ source_encoding=tokenizer(
33
+ main_news,
34
+ max_length=784,
35
+ padding="max_length",
36
+ truncation=True,
37
+ return_attention_mask=True,
38
+ add_special_tokens=True,
39
+ return_tensors="pt")
40
+
41
+ generated_ids=model.generate(
42
+ input_ids=source_encoding["input_ids"],
43
+ attention_mask=source_encoding["attention_mask"],
44
+ num_beams=2,
45
+ max_length=120,
46
+ repetition_penalty=2.5,
47
+ length_penalty=2.0,
48
+ early_stopping=True,
49
+ use_cache=True
50
+ )
51
+
52
+ preds=[tokenizer.decode(gen_id, skip_special_tokens=True, clean_up_tokenization_spaces=True)
53
+ for gen_id in generated_ids]
54
+
55
+ return "".join(preds)
56
+ ```
57
+
58
+ ### Example 1
59
+ ```python
60
+ main_news= "Final etabının üçüncü karşılaşması 29 Nisan Pazartesi günü saat 18.00 ’ de Burhan Felek
61
+ Voleybol Salonu ’ nda oynanacak . Sezonu FIVB Kulüpler Dünya Şampiyonluğu ile açan ve CEV
62
+ Avrupa Şampiyonlar Ligi'ni üçüncü olarak tamamlayan VakıfBank Kadın Voleybol Takımı ,
63
+ Vestel Venus Sultanlar Ligi final serisi ikinci maçında Eczacıbaşı VitrA'yı VakıfBank
64
+ Spor Sarayı'nda 16-25 , 25-10 , 25-18 ve 25-17'lik setlerle 3-1 mağlup ederek seride durumu
65
+ 1-1 ' e getirdi . İlk setini 25-16 kaybettiği karşılaşmanın ikinci setinde etkili servisler
66
+ kullanan sarı-siyahlılar , teknik molasına 12-5 önde girdiği seti 25-10 almayı başardı .
67
+ Etkili servis performansını üçüncü sette de sürdüren VakıfBank , teknik molasına 12-5 önde
68
+ girdiği seti 25-18 alarak , karşılaşmada 2-1 öne geçti . Dördüncü sette rakibinin geri dönüşüne
69
+ izin vermeyen VakıfBank , seti 25-17 , maçı da 3-1 kazanarak seride durumu eşitledi."
70
+
71
+ generate_summary(main_news)
72
+
73
+ #original summary -> "Vestel Venus Sultanlar Ligi final etabı ikinci karşılaşmasında VakıfBank
74
+ kendi sahasında Eczacıbaşı VitrA'yı 3-1 mağlup etti ve seride durumu 1-1 ' e getirdi ."
75
+
76
+ #output -> "CEV Avrupa Şampiyonlar Ligi'ni üçüncü olarak tamamlayan VakıfBank Kadın Voleybol Takımı,
77
+ Vestel Venus Sultanlar Ligi final serisi ikinci maçında Eczacıbaşı VitrA'yı 3-1 mağlup
78
+ ederek seride durumu 1-1'e getirdi."
79
+ ```
80
+
81
+ ### Example 2
82
+ ```python
83
+ main_news="2023'te yerli tank motoru : Bir taraftan da tankın motorunu yerlileştirmeye çalıştıklarını
84
+ ifade eden Öztürk , şu değerlendirmelerde bulundu : `` Bin 500 beygirlik , şanzımanıyla beraber
85
+ motoru yerlileştirmeye çalışıyoruz . Bu da bir aksilik çıkmazsa ilk tankımızın üzerine
86
+ 2023'te koyacağız . Bundan sonra hiçbir ülkeye bağımlılığımız kalmadan bu araçları üretmeye
87
+ devam edeceğiz . Sorumluluğumuzun ağır olduğunu biliyoruz . Ülkemize hizmet etmeye çalışıyoruz .
88
+ Bunu daha da ileriye götürmek için elimizden gelen çabayı sarf ediyoruz . Ama bu tek başınıza
89
+ yapılan bir operasyon değil . Türkiye'deki yerli firmalarla beraber ortaklaşa bu işi yürütmeye çalışıyoruz."
90
+
91
+ generate_summary(main_news)
92
+
93
+ #output -> "TÜRKİYE'de bir taraftan da tankın motorunu yerlileştirmeye çalıştıklarını belirten Öztürk,
94
+ `` Bin 500 beygirlik, şanzımanıyla beraber motoru yerlileştirmeye çalışıyoruz. Bu da bir
95
+ aksilik çıkmazsa ilk tankımızın üzerine 2023'te koyacağız.'' dedi."
96
+ ```
97
+
98
+ Created by Özcan Gündeş ✌️
99
+ ---
100
+
101
+ Twitter: <a href="https://twitter.com/ozcangundes" target="blank"><img align="center" src="https://cdn.jsdelivr.net/npm/simple-icons@3.0.1/icons/twitter.svg" alt="ozcangundes" height="30" width="30" /></a>
102
+ Linkedin: <a href="https://www.linkedin.com/in/%C3%B6zcan-g%C3%BCnde%C5%9F-7693055b/" target="blank"><img align="center" src="https://cdn.jsdelivr.net/npm/simple-icons@3.0.1/icons/linkedin.svg" alt="13198517" height="30" width="30" /></a>
103
+ Medium: <a href="https://medium.com/@ozcangundes" target="blank"><img align="center" src="https://cdn.jsdelivr.net/npm/simple-icons@3.0.1/icons/medium.svg" alt="@ozcangundes" height="30" width="30" /></a>
104
+ Github: <a href="https://github.com/ozcangundes" target="blank"><img align="center" src="https://cdn.jsdelivr.net/npm/simple-icons@3.0.1/icons/github.svg" alt="@ozcangundes" height="30" width="30" /></a>