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 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
# Generated content DO NOT EDIT
class Model:
    """
    Base class for all models

    The model represents the actual tokenization algorithm. This is the part that
    will contain and manage the learned vocabulary.

    This class cannot be constructed directly. Please use one of the concrete models.
    """
    def __init__(self):
        pass

    def __getstate__(self):
        """ """
        pass

    def __setstate__(self, state):
        """ """
        pass

    def get_trainer(self):
        """
        Get the associated :class:`~tokenizers.trainers.Trainer`

        Retrieve the :class:`~tokenizers.trainers.Trainer` associated to this
        :class:`~tokenizers.models.Model`.

        Returns:
            :class:`~tokenizers.trainers.Trainer`: The Trainer used to train this model
        """
        pass

    def id_to_token(self, id):
        """
        Get the token associated to an ID

        Args:
            id (:obj:`int`):
                An ID to convert to a token

        Returns:
            :obj:`str`: The token associated to the ID
        """
        pass

    def save(self, folder, prefix):
        """
        Save the current model

        Save the current model in the given folder, using the given prefix for the various
        files that will get created.
        Any file with the same name that already exists in this folder will be overwritten.

        Args:
            folder (:obj:`str`):
                The path to the target folder in which to save the various files

            prefix (:obj:`str`, `optional`):
                An optional prefix, used to prefix each file name

        Returns:
            :obj:`List[str]`: The list of saved files
        """
        pass

    def token_to_id(self, tokens):
        """
        Get the ID associated to a token

        Args:
            token (:obj:`str`):
                A token to convert to an ID

        Returns:
            :obj:`int`: The ID associated to the token
        """
        pass

    def tokenize(self, sequence):
        """
        Tokenize a sequence

        Args:
            sequence (:obj:`str`):
                A sequence to tokenize

        Returns:
            A :obj:`List` of :class:`~tokenizers.Token`: The generated tokens
        """
        pass

class BPE(Model):
    """
    An implementation of the BPE (Byte-Pair Encoding) algorithm

    Args:
        vocab (:obj:`Dict[str, int]`, `optional`):
            A dictionary of string keys and their ids :obj:`{"am": 0,...}`

        merges (:obj:`List[Tuple[str, str]]`, `optional`):
            A list of pairs of tokens (:obj:`Tuple[str, str]`) :obj:`[("a", "b"),...]`

        cache_capacity (:obj:`int`, `optional`):
            The number of words that the BPE cache can contain. The cache allows
            to speed-up the process by keeping the result of the merge operations
            for a number of words.

        dropout (:obj:`float`, `optional`):
            A float between 0 and 1 that represents the BPE dropout to use.

        unk_token (:obj:`str`, `optional`):
            The unknown token to be used by the model.

        continuing_subword_prefix (:obj:`str`, `optional`):
            The prefix to attach to subword units that don't represent a beginning of word.

        end_of_word_suffix (:obj:`str`, `optional`):
            The suffix to attach to subword units that represent an end of word.

        fuse_unk (:obj:`bool`, `optional`):
            Whether to fuse any subsequent unknown tokens into a single one

        byte_fallback (:obj:`bool`, `optional`):
            Whether to use spm byte-fallback trick (defaults to False)

        ignore_merges (:obj:`bool`, `optional`):
            Whether or not to match tokens with the vocab before using merges.
    """
    def __init__(
        self,
        vocab=None,
        merges=None,
        cache_capacity=None,
        dropout=None,
        unk_token=None,
        continuing_subword_prefix=None,
        end_of_word_suffix=None,
        fuse_unk=None,
        byte_fallback=False,
        ignore_merges=False,
    ):
        pass

    def __getstate__(self):
        """ """
        pass

    def __setstate__(self, state):
        """ """
        pass

    @property
    def byte_fallback(self):
        """ """
        pass

    @byte_fallback.setter
    def byte_fallback(self, value):
        """ """
        pass

    @property
    def continuing_subword_prefix(self):
        """ """
        pass

    @continuing_subword_prefix.setter
    def continuing_subword_prefix(self, value):
        """ """
        pass

    @property
    def dropout(self):
        """ """
        pass

    @dropout.setter
    def dropout(self, value):
        """ """
        pass

    @property
    def end_of_word_suffix(self):
        """ """
        pass

    @end_of_word_suffix.setter
    def end_of_word_suffix(self, value):
        """ """
        pass

    @staticmethod
    def from_file(vocab, merges, **kwargs):
        """
        Instantiate a BPE model from the given files.

        This method is roughly equivalent to doing::

           vocab, merges = BPE.read_file(vocab_filename, merges_filename)
           bpe = BPE(vocab, merges)

        If you don't need to keep the :obj:`vocab, merges` values lying around,
        this method is more optimized than manually calling
        :meth:`~tokenizers.models.BPE.read_file` to initialize a :class:`~tokenizers.models.BPE`

        Args:
            vocab (:obj:`str`):
                The path to a :obj:`vocab.json` file

            merges (:obj:`str`):
                The path to a :obj:`merges.txt` file

        Returns:
            :class:`~tokenizers.models.BPE`: An instance of BPE loaded from these files
        """
        pass

    @property
    def fuse_unk(self):
        """ """
        pass

    @fuse_unk.setter
    def fuse_unk(self, value):
        """ """
        pass

    def get_trainer(self):
        """
        Get the associated :class:`~tokenizers.trainers.Trainer`

        Retrieve the :class:`~tokenizers.trainers.Trainer` associated to this
        :class:`~tokenizers.models.Model`.

        Returns:
            :class:`~tokenizers.trainers.Trainer`: The Trainer used to train this model
        """
        pass

    def id_to_token(self, id):
        """
        Get the token associated to an ID

        Args:
            id (:obj:`int`):
                An ID to convert to a token

        Returns:
            :obj:`str`: The token associated to the ID
        """
        pass

    @property
    def ignore_merges(self):
        """ """
        pass

    @ignore_merges.setter
    def ignore_merges(self, value):
        """ """
        pass

    @staticmethod
    def read_file(vocab, merges):
        """
        Read a :obj:`vocab.json` and a :obj:`merges.txt` files

        This method provides a way to read and parse the content of these files,
        returning the relevant data structures. If you want to instantiate some BPE models
        from memory, this method gives you the expected input from the standard files.

        Args:
            vocab (:obj:`str`):
                The path to a :obj:`vocab.json` file

            merges (:obj:`str`):
                The path to a :obj:`merges.txt` file

        Returns:
            A :obj:`Tuple` with the vocab and the merges:
                The vocabulary and merges loaded into memory
        """
        pass

    def save(self, folder, prefix):
        """
        Save the current model

        Save the current model in the given folder, using the given prefix for the various
        files that will get created.
        Any file with the same name that already exists in this folder will be overwritten.

        Args:
            folder (:obj:`str`):
                The path to the target folder in which to save the various files

            prefix (:obj:`str`, `optional`):
                An optional prefix, used to prefix each file name

        Returns:
            :obj:`List[str]`: The list of saved files
        """
        pass

    def token_to_id(self, tokens):
        """
        Get the ID associated to a token

        Args:
            token (:obj:`str`):
                A token to convert to an ID

        Returns:
            :obj:`int`: The ID associated to the token
        """
        pass

    def tokenize(self, sequence):
        """
        Tokenize a sequence

        Args:
            sequence (:obj:`str`):
                A sequence to tokenize

        Returns:
            A :obj:`List` of :class:`~tokenizers.Token`: The generated tokens
        """
        pass

    @property
    def unk_token(self):
        """ """
        pass

    @unk_token.setter
    def unk_token(self, value):
        """ """
        pass

class Unigram(Model):
    """
    An implementation of the Unigram algorithm

    Args:
        vocab (:obj:`List[Tuple[str, float]]`, `optional`, `optional`):
            A list of vocabulary items and their relative score [("am", -0.2442),...]
    """
    def __init__(self, vocab=None, unk_id=None, byte_fallback=None):
        pass

    def __getstate__(self):
        """ """
        pass

    def __setstate__(self, state):
        """ """
        pass

    def get_trainer(self):
        """
        Get the associated :class:`~tokenizers.trainers.Trainer`

        Retrieve the :class:`~tokenizers.trainers.Trainer` associated to this
        :class:`~tokenizers.models.Model`.

        Returns:
            :class:`~tokenizers.trainers.Trainer`: The Trainer used to train this model
        """
        pass

    def id_to_token(self, id):
        """
        Get the token associated to an ID

        Args:
            id (:obj:`int`):
                An ID to convert to a token

        Returns:
            :obj:`str`: The token associated to the ID
        """
        pass

    def save(self, folder, prefix):
        """
        Save the current model

        Save the current model in the given folder, using the given prefix for the various
        files that will get created.
        Any file with the same name that already exists in this folder will be overwritten.

        Args:
            folder (:obj:`str`):
                The path to the target folder in which to save the various files

            prefix (:obj:`str`, `optional`):
                An optional prefix, used to prefix each file name

        Returns:
            :obj:`List[str]`: The list of saved files
        """
        pass

    def token_to_id(self, tokens):
        """
        Get the ID associated to a token

        Args:
            token (:obj:`str`):
                A token to convert to an ID

        Returns:
            :obj:`int`: The ID associated to the token
        """
        pass

    def tokenize(self, sequence):
        """
        Tokenize a sequence

        Args:
            sequence (:obj:`str`):
                A sequence to tokenize

        Returns:
            A :obj:`List` of :class:`~tokenizers.Token`: The generated tokens
        """
        pass

class WordLevel(Model):
    """
    An implementation of the WordLevel algorithm

    Most simple tokenizer model based on mapping tokens to their corresponding id.

    Args:
        vocab (:obj:`str`, `optional`):
            A dictionary of string keys and their ids :obj:`{"am": 0,...}`

        unk_token (:obj:`str`, `optional`):
            The unknown token to be used by the model.
    """
    def __init__(self, vocab=None, unk_token=None):
        pass

    def __getstate__(self):
        """ """
        pass

    def __setstate__(self, state):
        """ """
        pass

    @staticmethod
    def from_file(vocab, unk_token=None):
        """
        Instantiate a WordLevel model from the given file

        This method is roughly equivalent to doing::

            vocab = WordLevel.read_file(vocab_filename)
            wordlevel = WordLevel(vocab)

        If you don't need to keep the :obj:`vocab` values lying around, this method is
        more optimized than manually calling :meth:`~tokenizers.models.WordLevel.read_file` to
        initialize a :class:`~tokenizers.models.WordLevel`

        Args:
            vocab (:obj:`str`):
                The path to a :obj:`vocab.json` file

        Returns:
            :class:`~tokenizers.models.WordLevel`: An instance of WordLevel loaded from file
        """
        pass

    def get_trainer(self):
        """
        Get the associated :class:`~tokenizers.trainers.Trainer`

        Retrieve the :class:`~tokenizers.trainers.Trainer` associated to this
        :class:`~tokenizers.models.Model`.

        Returns:
            :class:`~tokenizers.trainers.Trainer`: The Trainer used to train this model
        """
        pass

    def id_to_token(self, id):
        """
        Get the token associated to an ID

        Args:
            id (:obj:`int`):
                An ID to convert to a token

        Returns:
            :obj:`str`: The token associated to the ID
        """
        pass

    @staticmethod
    def read_file(vocab):
        """
        Read a :obj:`vocab.json`

        This method provides a way to read and parse the content of a vocabulary file,
        returning the relevant data structures. If you want to instantiate some WordLevel models
        from memory, this method gives you the expected input from the standard files.

        Args:
            vocab (:obj:`str`):
                The path to a :obj:`vocab.json` file

        Returns:
            :obj:`Dict[str, int]`: The vocabulary as a :obj:`dict`
        """
        pass

    def save(self, folder, prefix):
        """
        Save the current model

        Save the current model in the given folder, using the given prefix for the various
        files that will get created.
        Any file with the same name that already exists in this folder will be overwritten.

        Args:
            folder (:obj:`str`):
                The path to the target folder in which to save the various files

            prefix (:obj:`str`, `optional`):
                An optional prefix, used to prefix each file name

        Returns:
            :obj:`List[str]`: The list of saved files
        """
        pass

    def token_to_id(self, tokens):
        """
        Get the ID associated to a token

        Args:
            token (:obj:`str`):
                A token to convert to an ID

        Returns:
            :obj:`int`: The ID associated to the token
        """
        pass

    def tokenize(self, sequence):
        """
        Tokenize a sequence

        Args:
            sequence (:obj:`str`):
                A sequence to tokenize

        Returns:
            A :obj:`List` of :class:`~tokenizers.Token`: The generated tokens
        """
        pass

    @property
    def unk_token(self):
        """ """
        pass

    @unk_token.setter
    def unk_token(self, value):
        """ """
        pass

class WordPiece(Model):
    """
    An implementation of the WordPiece algorithm

    Args:
        vocab (:obj:`Dict[str, int]`, `optional`):
            A dictionary of string keys and their ids :obj:`{"am": 0,...}`

        unk_token (:obj:`str`, `optional`):
            The unknown token to be used by the model.

        max_input_chars_per_word (:obj:`int`, `optional`):
            The maximum number of characters to authorize in a single word.
    """
    def __init__(self, vocab=None, unk_token="[UNK]", max_input_chars_per_word=100, continuing_subword_prefix="##"):
        pass

    def __getstate__(self):
        """ """
        pass

    def __setstate__(self, state):
        """ """
        pass

    @property
    def continuing_subword_prefix(self):
        """ """
        pass

    @continuing_subword_prefix.setter
    def continuing_subword_prefix(self, value):
        """ """
        pass

    @staticmethod
    def from_file(vocab, **kwargs):
        """
        Instantiate a WordPiece model from the given file

        This method is roughly equivalent to doing::

            vocab = WordPiece.read_file(vocab_filename)
            wordpiece = WordPiece(vocab)

        If you don't need to keep the :obj:`vocab` values lying around, this method is
        more optimized than manually calling :meth:`~tokenizers.models.WordPiece.read_file` to
        initialize a :class:`~tokenizers.models.WordPiece`

        Args:
            vocab (:obj:`str`):
                The path to a :obj:`vocab.txt` file

        Returns:
            :class:`~tokenizers.models.WordPiece`: An instance of WordPiece loaded from file
        """
        pass

    def get_trainer(self):
        """
        Get the associated :class:`~tokenizers.trainers.Trainer`

        Retrieve the :class:`~tokenizers.trainers.Trainer` associated to this
        :class:`~tokenizers.models.Model`.

        Returns:
            :class:`~tokenizers.trainers.Trainer`: The Trainer used to train this model
        """
        pass

    def id_to_token(self, id):
        """
        Get the token associated to an ID

        Args:
            id (:obj:`int`):
                An ID to convert to a token

        Returns:
            :obj:`str`: The token associated to the ID
        """
        pass

    @property
    def max_input_chars_per_word(self):
        """ """
        pass

    @max_input_chars_per_word.setter
    def max_input_chars_per_word(self, value):
        """ """
        pass

    @staticmethod
    def read_file(vocab):
        """
        Read a :obj:`vocab.txt` file

        This method provides a way to read and parse the content of a standard `vocab.txt`
        file as used by the WordPiece Model, returning the relevant data structures. If you
        want to instantiate some WordPiece models from memory, this method gives you the
        expected input from the standard files.

        Args:
            vocab (:obj:`str`):
                The path to a :obj:`vocab.txt` file

        Returns:
            :obj:`Dict[str, int]`: The vocabulary as a :obj:`dict`
        """
        pass

    def save(self, folder, prefix):
        """
        Save the current model

        Save the current model in the given folder, using the given prefix for the various
        files that will get created.
        Any file with the same name that already exists in this folder will be overwritten.

        Args:
            folder (:obj:`str`):
                The path to the target folder in which to save the various files

            prefix (:obj:`str`, `optional`):
                An optional prefix, used to prefix each file name

        Returns:
            :obj:`List[str]`: The list of saved files
        """
        pass

    def token_to_id(self, tokens):
        """
        Get the ID associated to a token

        Args:
            token (:obj:`str`):
                A token to convert to an ID

        Returns:
            :obj:`int`: The ID associated to the token
        """
        pass

    def tokenize(self, sequence):
        """
        Tokenize a sequence

        Args:
            sequence (:obj:`str`):
                A sequence to tokenize

        Returns:
            A :obj:`List` of :class:`~tokenizers.Token`: The generated tokens
        """
        pass

    @property
    def unk_token(self):
        """ """
        pass

    @unk_token.setter
    def unk_token(self, value):
        """ """
        pass