.. raw:: html
.. raw:: latex
\diilbookstyleinputcell
.. code:: python
#@save
d2l.DATA_HUB['time_machine'] = (d2l.DATA_URL + 'timemachine.txt',
'090b5e7e70c295757f55df93cb0a180b9691891a')
def read_time_machine(): #@save
"""Zaman makinesi veri kümesini bir metin satırı listesine yükleyin."""
with open(d2l.download('time_machine'), 'r') as f:
lines = f.readlines()
return [re.sub('[^A-Za-z]+', ' ', line).strip().lower() for line in lines]
lines = read_time_machine()
print(f'# text lines: {len(lines)}')
print(lines[0])
print(lines[10])
.. raw:: latex
\diilbookstyleoutputcell
.. parsed-literal::
:class: output
# text lines: 3221
the time machine by h g wells
twinkled and his usually pale face was flushed and animated the
.. raw:: html
.. raw:: html
.. raw:: latex
\diilbookstyleinputcell
.. code:: python
#@save
d2l.DATA_HUB['time_machine'] = (d2l.DATA_URL + 'timemachine.txt',
'090b5e7e70c295757f55df93cb0a180b9691891a')
def read_time_machine(): #@save
"""Zaman makinesi veri kümesini bir metin satırı listesine yükleyin."""
with open(d2l.download('time_machine'), 'r') as f:
lines = f.readlines()
return [re.sub('[^A-Za-z]+', ' ', line).strip().lower() for line in lines]
lines = read_time_machine()
print(f'# text lines: {len(lines)}')
print(lines[0])
print(lines[10])
.. raw:: latex
\diilbookstyleoutputcell
.. parsed-literal::
:class: output
# text lines: 3221
the time machine by h g wells
twinkled and his usually pale face was flushed and animated the
.. raw:: html
.. raw:: html
.. raw:: latex
\diilbookstyleinputcell
.. code:: python
#@save
d2l.DATA_HUB['time_machine'] = (d2l.DATA_URL + 'timemachine.txt',
'090b5e7e70c295757f55df93cb0a180b9691891a')
def read_time_machine(): #@save
"""Zaman makinesi veri kümesini bir metin satırı listesine yükleyin."""
with open(d2l.download('time_machine'), 'r') as f:
lines = f.readlines()
return [re.sub('[^A-Za-z]+', ' ', line).strip().lower() for line in lines]
lines = read_time_machine()
print(f'# text lines: {len(lines)}')
print(lines[0])
print(lines[10])
.. raw:: latex
\diilbookstyleoutputcell
.. parsed-literal::
:class: output
# text lines: 3221
the time machine by h g wells
twinkled and his usually pale face was flushed and animated the
.. raw:: html
.. raw:: html
Andıçlama
---------
Aşağıdaki ``tokenize`` işlevi, girdi olarak bir liste (``lines``) alır
ve burada her eleman bir metin dizisidir (örneğin, bir metin satırı).
Her metin dizisi bir andıç listesine bölünür. *Andıç* metindeki temel
birimdir. Sonunda, her andıcın bir dizgi olduğu andıç listelerinin bir
listesi döndürülür.
.. raw:: html
.. raw:: html
.. raw:: latex
\diilbookstyleinputcell
.. code:: python
def tokenize(lines, token='word'): #@save
"""Metin satırlarını kelime veya karakter belirteçlerine ayırın."""
if token == 'word':
return [line.split() for line in lines]
elif token == 'char':
return [list(line) for line in lines]
else:
print('ERROR: unknown token type: ' + token)
tokens = tokenize(lines)
for i in range(11):
print(tokens[i])
.. raw:: latex
\diilbookstyleoutputcell
.. parsed-literal::
:class: output
['the', 'time', 'machine', 'by', 'h', 'g', 'wells']
[]
[]
[]
[]
['i']
[]
[]
['the', 'time', 'traveller', 'for', 'so', 'it', 'will', 'be', 'convenient', 'to', 'speak', 'of', 'him']
['was', 'expounding', 'a', 'recondite', 'matter', 'to', 'us', 'his', 'grey', 'eyes', 'shone', 'and']
['twinkled', 'and', 'his', 'usually', 'pale', 'face', 'was', 'flushed', 'and', 'animated', 'the']
.. raw:: html
.. raw:: html
.. raw:: latex
\diilbookstyleinputcell
.. code:: python
def tokenize(lines, token='word'): #@save
"""Metin satırlarını kelime veya karakter belirteçlerine ayırın."""
if token == 'word':
return [line.split() for line in lines]
elif token == 'char':
return [list(line) for line in lines]
else:
print('ERROR: unknown token type: ' + token)
tokens = tokenize(lines)
for i in range(11):
print(tokens[i])
.. raw:: latex
\diilbookstyleoutputcell
.. parsed-literal::
:class: output
['the', 'time', 'machine', 'by', 'h', 'g', 'wells']
[]
[]
[]
[]
['i']
[]
[]
['the', 'time', 'traveller', 'for', 'so', 'it', 'will', 'be', 'convenient', 'to', 'speak', 'of', 'him']
['was', 'expounding', 'a', 'recondite', 'matter', 'to', 'us', 'his', 'grey', 'eyes', 'shone', 'and']
['twinkled', 'and', 'his', 'usually', 'pale', 'face', 'was', 'flushed', 'and', 'animated', 'the']
.. raw:: html
.. raw:: html
.. raw:: latex
\diilbookstyleinputcell
.. code:: python
def tokenize(lines, token='word'): #@save
"""Metin satırlarını kelime veya karakter belirteçlerine ayırın."""
if token == 'word':
return [line.split() for line in lines]
elif token == 'char':
return [list(line) for line in lines]
else:
print('ERROR: unknown token type: ' + token)
tokens = tokenize(lines)
for i in range(11):
print(tokens[i])
.. raw:: latex
\diilbookstyleoutputcell
.. parsed-literal::
:class: output
['the', 'time', 'machine', 'by', 'h', 'g', 'wells']
[]
[]
[]
[]
['i']
[]
[]
['the', 'time', 'traveller', 'for', 'so', 'it', 'will', 'be', 'convenient', 'to', 'speak', 'of', 'him']
['was', 'expounding', 'a', 'recondite', 'matter', 'to', 'us', 'his', 'grey', 'eyes', 'shone', 'and']
['twinkled', 'and', 'his', 'usually', 'pale', 'face', 'was', 'flushed', 'and', 'animated', 'the']
.. raw:: html
.. raw:: html
Kelime Dağarcığı
----------------
Andıcın dizgi tipi, sayısal girdiler alan modeller tarafından
kullanılmak için elverişsizdir. Şimdi dizgi andıçlarını 0'dan başlayan
sayısal indekslere eşlemek için, genellikle *kelime dağarcığı* olarak
adlandırılan bir sözlük oluşturalım. Bunu yapmak için, önce eğitim
kümesindeki tüm belgelerdeki benzersiz andıçları, yani bir
*külliyat*\ ı, sayarız ve daha sonra her benzersiz andıca frekansına
göre sayısal bir indeks atarız. Genellikle nadiren ortaya çıkan andıçlar
karmaşıklığı azaltmak için kaldırılır. Külliyat içinde bulunmayan veya
kaldırılan herhangi bir andıç, bilinmeyen özel bir andıç “