/usr/local/lib/python3.6/site-packages/sacremoses/__pycache__
NameSizeModeActions
chinese.cpython-36.pyc147100644editdlrm
cli.cpython-36.pyc65190644editdlrm
corpus.cpython-36.pyc49150644editdlrm
indic.cpython-36.pyc9490644editdlrm
normalize.cpython-36.pyc48290644editdlrm
sent_tokenize.cpython-36.pyc7210644editdlrm
subwords.cpython-36.pyc46500644editdlrm
tokenize.cpython-36.pyc165930644editdlrm
truecase.cpython-36.pyc117780644editdlrm
util.cpython-36.pyc51300644editdlrm
__init__.cpython-36.pyc2990644editdlrm
__main__.cpython-36.pyc2240644editdlrm
Edit: /usr/local/lib/python3.6/site-packages/sacremoses/__pycache__/subwords.cpython-36.pyc (4650B)
3 Eg @sPddlmZddlZddlmZmZddlmZddlm Z Gddde Z dS))print_functionN)Counter defaultdict)reduce)pairwisec@sLeZdZdZddZdddZddZd d Zd d Zd dZ dddZ dS)SubwordTokenizerzd This is a Python port of the Subword NMT from https://github.com/rsennrich/subword-nmt cCs.|j||_|j\|_|_tj|j|_dS)N)get_vocabularyvocabget_pair_statisticsstatsindicescopydeepcopyZ big_stats)selffilenamer=/usr/local/lib/python3.6/site-packages/sacremoses/subwords.py__init__s zSubwordTokenizer.__init__Fc Cst}t|R}|rJxF|D]*}|jjd\}}||t|7<qWn|j|jjWdQRXtdd|jD}|jS)N cSs0i|](\}}|t|dd|ddfqS)Nur)tuple).0kvrrr $sz3SubwordTokenizer.get_vocabulary..) ropenstripsplitintupdatereaditems most_common)rris_dictr Zfinlinewordcountrrrrs  zSubwordTokenizer.get_vocabularycCsxt}tdd}x\t|jD]N\}\}}x@t|D]4\}}|||f|7<|||f|d7<q4WqW||fS)z5Count frequency of all symbol pairs, and create indexcSstS)N)rrrrr-sz6SubwordTokenizer.get_pair_statistics..r)rr enumerater r)rr r ir&freqprevcurrrrrr (s  z$SubwordTokenizer.get_pair_statisticscsD|\dj|jddfdd}t||dd|dfS) z From https://stackoverflow.com/a/40367074/610569 >>> modify_token(('s', 'h', 'e', 'r', 'l', 'o', 'c', 'k'), ('h', 'e')) ('S', 'he', 'r', 'l', 'o', 'c', 'k') \z\\cs0|dkr&|kr&|ddfS||fS)Nrrrr)acce)firstpair_strsecondrrr(?s&z/SubwordTokenizer.modify_token..rNr)joinreplacer)rtokenpairfr)r2r3r4r modify_token6szSubwordTokenizer.modify_tokencCshg}x^|j|jD]L\}}|dkr&q|j|\}}|j||}||f|j|<|j||||fqW|S)zJReplace all occurrences of a symbol pair ('A', 'B') with a new symbol 'AB'r)r r"r r:append)rr8changesjr+r&Znew_wordrrr replace_pairEs zSubwordTokenizer.replace_pairc CsLd|j|<t|j|<|\}}||}x|D]\}}}} d} x$y|j|| } Wntk rjPYnX| t|dko|| d|kr\| r|| d| d} |j| | 8<|j| |d8<| t|dkrR|| d|ks| t|dks|| d|krR|| d| d} |j| | 8<|j| |d8<| d7} qD| d7} qDWd} xy|j|| } Wntk rPYnX| r|| d| d} |j| | 7<|j| |d7<| t|dkr6|| d|kr6|| | d} |j| | 7<|j| |d7<| d7} qnWq.WdS)z Minimally update the indices and frequency of symbol pairs if we merge a pair of symbols, only pairs that overlap with occurrences of this pair are affected, and need to be updated. rrN)r rr index ValueErrorlen) rr8changedr2r4Znew_pairr=r&Zold_wordr+r*r,Znexrrrupdate_pair_statisticsQsP  "   $z'SubwordTokenizer.update_pair_statisticsr?rNc Csxt|jjd}x`t|D]T}|jj|}xB|D]:\}} |j|} |j|| d|j|<|j||kr2dSq2WqWdS)N r)maxr valuesranger#r>rE) rZ num_symbolsZmin_freqZjumpr$ thresholdr*Zmost_freq_tokensr7r'r<rrrlearns    zSubwordTokenizer.learn)F)r?rN) __name__ __module__ __qualname____doc__rrr r:r>rErKrrrrr s  [r) __future__rr collectionsrr functoolsrZsacremoses.utilrobjectrrrrrs