Textaugment adalah perpustakaan Python 3 untuk menambah teks untuk aplikasi pemrosesan bahasa alami. Textaugment berdiri di bahu raksasa NLTK, Gensim V3.x, dan TextBlob dan bermain dengan baik dengan mereka.
Kutip makalah ini saat menggunakan perpustakaan ini. Versi arxiv
@inproceedings{marivate2020improving,
title={Improving short text classification through global augmentation methods},
author={Marivate, Vukosi and Sefara, Tshephisho},
booktitle={International Cross-Domain Conference for Machine Learning and Knowledge Extraction},
pages={385--399},
year={2020},
organization={Springer}
}
Meningkatkan klasifikasi teks pendek melalui metode augmentasi global .
Paket perangkat lunak berikut adalah dependensi dan akan diinstal secara otomatis.
$ pip install numpy nltk gensim==3.8.3 textblob googletrans
Kode berikut mengunduh nltk corpus untuk WordNet.
nltk . download ( 'wordnet' )Kode berikut mengunduh NLTK Tokenizer. Tokenizer ini membagi teks menjadi daftar kalimat dengan menggunakan algoritma yang tidak diawasi untuk membangun model untuk kata -kata singkatan, kolokasi, dan kata -kata yang memulai kalimat.
nltk . download ( 'punkt' )Kode berikut mengunduh model tagger bagian nltk nltk. Tagger bagian-of-speech memproses urutan kata, dan melampirkan bagian tag ucapan untuk setiap kata.
nltk . download ( 'averaged_perceptron_tagger' )Gunakan Gensim untuk memuat model Word2VEC pra-terlatih. Seperti Google News dari Google Drive.
import gensim
model = gensim . models . KeyedVectors . load_word2vec_format ( './GoogleNews-vectors-negative300.bin' , binary = True )Anda juga dapat menggunakan Gensim untuk memuat model FastText English dan multibahasa Facebook
import gensim
model = gensim.models.fasttext.load_facebook_model('./cc.en.300.bin.gz')
Atau melatih satu dari awal menggunakan data Anda atau dataset publik berikut:
Text8 Wiki
Dataset dari "satu miliar tolok ukur pemodelan bahasa kata"
Instal dari PIP [Direkomendasikan]
$ pip install textaugment
or install latest release
$ pip install [email protected]:dsfsi/textaugment.gitInstal dari sumber
$ git clone [email protected]:dsfsi/textaugment.git
$ cd textaugment
$ python setup.py installAda tiga jenis augmentasi yang dapat digunakan:
from textaugment import Word2vec from textaugment import Fasttext from textaugment import Wordnet from textaugment import Translate Lihat contoh noten ini
Contoh Dasar
> >> from textaugment import Word2vec , Fasttext
> >> t = Word2vec ( model = 'path/to/gensim/model' or 'gensim model itself' )
> >> t . augment ( 'The stories are good' )
The films are good
> >> t = Fasttext ( model = 'path/to/gensim/model' or 'gensim model itself' )
> >> t . augment ( 'The stories are good' )
The films are goodContoh lanjutan
> >> runs = 1 # By default.
> >> v = False # verbose mode to replace all the words. If enabled runs is not effective. Used in this paper (https://www.cs.cmu.edu/~diyiy/docs/emnlp_wang_2015.pdf)
> >> p = 0.5 # The probability of success of an individual trial. (0.1<p<1.0), default is 0.5. Used by Geometric distribution to selects words from a sentence.
> >> word = Word2vec ( model = 'path/to/gensim/model' or 'gensim model itself' , runs = 5 , v = False , p = 0.5 )
> >> word . augment ( 'The stories are good' , top_n = 10 )
The movies are excellent
> >> fast = Fasttext ( model = 'path/to/gensim/model' or 'gensim model itself' , runs = 5 , v = False , p = 0.5 )
> >> fast . augment ( 'The stories are good' , top_n = 10 )
The movies are excellent Contoh Dasar
> >> import nltk
> >> nltk . download ( 'punkt' )
> >> nltk . download ( 'wordnet' )
> >> from textaugment import Wordnet
> >> t = Wordnet ()
> >> t . augment ( 'In the afternoon, John is going to town' )
In the afternoon , John is walking to townContoh lanjutan
> >> v = True # enable verbs augmentation. By default is True.
> >> n = False # enable nouns augmentation. By default is False.
> >> runs = 1 # number of times to augment a sentence. By default is 1.
> >> p = 0.5 # The probability of success of an individual trial. (0.1<p<1.0), default is 0.5. Used by Geometric distribution to selects words from a sentence.
> >> t = Wordnet ( v = False , n = True , p = 0.5 )
> >> t . augment ( 'In the afternoon, John is going to town' , top_n = 10 )
In the afternoon , Joseph is going to town .Contoh
> >> src = "en" # source language of the sentence
> >> to = "fr" # target language
> >> from textaugment import Translate
> >> t = Translate ( src = "en" , to = "fr" )
> >> t . augment ( 'In the afternoon, John is going to town' )
In the afternoon John goes to townhttps://www.aclweb.org/anthology/d19-1670.pdf
Lihat contoh noten ini
Pilih secara acak N kata -kata dari kalimat yang tidak menghentikan kata -kata. Ganti masing -masing kata ini dengan salah satu sinonimnya yang dipilih secara acak.
Contoh Dasar
> >> from textaugment import EDA
> >> t = EDA ()
> >> t . synonym_replacement ( "John is going to town" , top_n = 10 )
John is give out to town Hapus setiap kata secara acak dalam kalimat dengan probabilitas p .
Contoh Dasar
> >> from textaugment import EDA
> >> t = EDA ()
> >> t . random_deletion ( "John is going to town" , p = 0.2 )
is going to town Pilih dua kata secara acak dalam kalimat dan bertukar posisi mereka. Lakukan ini N kali.
Contoh Dasar
> >> from textaugment import EDA
> >> t = EDA ()
> >> t . random_swap ( "John is going to town" )
John town going to is Temukan sinonim acak dari kata acak dalam kalimat yang bukan kata berhenti. Masukkan sinonim ke posisi acak dalam kalimat. Lakukan ini N kali
Contoh Dasar
> >> from textaugment import EDA
> >> t = EDA ()
> >> t . random_insertion ( "John is going to town" )
John is going to make up townIni adalah implementasi Aeda oleh Karimi et al, varian EDA. Ini didasarkan pada penyisipan acak tanda baca.
https://aclanthology.org/2021.findings-nemnlp.234.pdf
Lihat contoh noten ini
Contoh Dasar
> >> from textaugment import AEDA
> >> t = AEDA ()
> >> t . punct_insertion ( "John is going to town" )
! John is going to townIni adalah implementasi augmentasi mixup oleh Hongyi Zhang, Moustapha Cisse, Yann Dauphin, David Lopez-Paz yang diadaptasi dengan NLP.
Digunakan dalam menambah data dengan mixup untuk klasifikasi kalimat: studi empiris.
MixUp adalah prinsip augmentasi data generik dan mudah. Intinya, MixUp melatih jaringan saraf tentang kombinasi cembung dari pasangan contoh dan labelnya. Dengan melakukan itu, MixUp mengatur jaringan saraf untuk mendukung perilaku linier sederhana di antara contoh-contoh pelatihan.
Lihat contoh noten ini
Kutip makalah ini saat menggunakan perpustakaan ini. Versi arxiv
@inproceedings{marivate2020improving,
title={Improving short text classification through global augmentation methods},
author={Marivate, Vukosi and Sefara, Tshephisho},
booktitle={International Cross-Domain Conference for Machine Learning and Knowledge Extraction},
pages={385--399},
year={2020},
organization={Springer}
}
MIT berlisensi. Lihat file lisensi yang dibundel untuk lebih jelasnya.