@@ -64,8 +64,8 @@ pip install datasets
6464
6565次に、テキストをトークナイザに渡します:
6666
67- ``` python
68- >> > encoded_input = tokenizer(" 魔法使いの事には干渉しないでください、彼らは微妙で怒りっぽいです。 " )
67+ ``` py
68+ >> > encoded_input = tokenizer(" Do not meddle in the affairs of wizards, for they are subtle and quick to anger. " )
6969>> > print (encoded_input)
7070{' input_ids' : [101 , 2079 , 2025 , 19960 , 10362 , 1999 , 1996 , 3821 , 1997 , 16657 , 1010 , 2005 , 2027 , 2024 , 11259 , 1998 , 4248 , 2000 , 4963 , 1012 , 102 ],
7171 ' token_type_ids' : [0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ],
@@ -90,11 +90,11 @@ pip install datasets
9090
9191複数の文章を前処理する場合、トークナイザにリストとして渡してください:
9292
93- ``` python
93+ ``` py
9494>> > batch_sentences = [
95- ... " でも、セカンドブレックファーストはどうなるの? " ,
96- ... " ピップ、セカンドブレックファーストのことを知っているかどうかはわからないと思うよ。 " ,
97- ... " イレブンジーズはどうなの? " ,
95+ ... " But what about second breakfast? " ,
96+ ... " Don't think he knows about second breakfast, Pip. " ,
97+ ... " What about elevensies? " ,
9898... ]
9999>> > encoded_inputs = tokenizer(batch_sentences)
100100>> > print (encoded_inputs)
@@ -116,11 +116,11 @@ pip install datasets
116116
117117バッチ内の短いシーケンスを最長のシーケンスに合わせるために、` padding ` パラメータを` True ` に設定します:
118118
119- ``` python
119+ ``` py
120120>> > batch_sentences = [
121- ... " でもセカンドブレックファーストはどうなるの? " ,
122- ... " セカンドブレックファーストについては知らないと思う、ピップ。 " ,
123- ... " イレブンジーズはどうなの? " ,
121+ ... " But what about second breakfast? " ,
122+ ... " Don't think he knows about second breakfast, Pip. " ,
123+ ... " What about elevensies? " ,
124124... ]
125125>> > encoded_input = tokenizer(batch_sentences, padding = True )
126126>> > print (encoded_input)
@@ -143,11 +143,11 @@ pip install datasets
143143
144144モデルが受け入れる最大の長さにシーケンスを切り詰めるには、` truncation ` パラメータを` True ` に設定します:
145145
146- ``` python
146+ ``` py
147147>> > batch_sentences = [
148- ... " でも、セカンドブレックファーストはどうなるの? " ,
149- ... " セカンドブレックファーストについては知らないと思う、ピップ。 " ,
150- ... " イレブンジーズはどうなの? " ,
148+ ... " But what about second breakfast? " ,
149+ ... " Don't think he knows about second breakfast, Pip. " ,
150+ ... " What about elevensies? " ,
151151... ]
152152>> > encoded_input = tokenizer(batch_sentences, padding = True , truncation = True )
153153>> > print (encoded_input)
@@ -177,11 +177,11 @@ pip install datasets
177177<frameworkcontent >
178178<pt >
179179
180- ``` python
180+ ``` py
181181>> > batch_sentences = [
182- ... " でも、セカンドブレックファーストはどうなるの? " ,
183- ... " ピップ、セカンドブレックファーストについては知っていないと思うよ。 " ,
184- ... " イレブンジーズはどうなの? " ,
182+ ... " But what about second breakfast? " ,
183+ ... " Don't think he knows about second breakfast, Pip. " ,
184+ ... " What about elevensies? " ,
185185... ]
186186>> > encoded_input = tokenizer(batch_sentences, padding = True , truncation = True , return_tensors = " pt" )
187187>> > print (encoded_input)
0 commit comments