/usr/local/lib64/python3.6/site-packages/tokenizers/tools/__pycache__
Edit: /usr/local/lib64/python3.6/site-packages/tokenizers/tools/__pycache__/visualizer.cpython-36.pyc (11513B)
3
Eg9 @ s d dl Z d dlZd dlZd dlmZmZmZmZmZm Z m
Z
d dlmZ d dlmZ d dl
mZmZ e jjeZe jjedZeeZej ZW dQ R X G dd dZee Zeee ZG d d
d
e
ZG dd dZG d
d dZG dd dZ efee! e!dddZ"dS ) N)ListOptionalTupleDictCallableAny
NamedTuple)Template)r ) TokenizerEncodingzvisualizer-styles.cssc @ s, e Zd ZU eeeeeedddZdS )
Annotation)startendlabelc C s || _ || _|| _d S )N)r
r r )selfr
r r r G/usr/local/lib64/python3.6/site-packages/tokenizers/tools/visualizer.py__init__ s zAnnotation.__init__N) __name__
__module____qualname__intr
r r strr r r r r r s
r c @ s e Zd ZU ee ee dS )CharStateKeyN)r r r r r token_ixanno_ixr r r r r s
r c @ sD e Zd ZU ee dd Zedd Zedd Z e
ddd Zd
S ) CharStatec C s || _ d | _g | _d S )N)char_ixr tokens)r r r r r r ' s zCharState.__init__c C s t | jdkr| jd S d S )Nr )lenr )r r r r r - s zCharState.token_ixc C s t | jdkS )zJ
BPE tokenizers can output more than one token for a char
)r r )r r r r
is_multitoken1 s zCharState.is_multitoken)returnc C s t | j| jdS )N)r r )r r r )r r r r
partition_key8 s zCharState.partition_keyN)r r r r r r r propertyr r! r r# r r r r r $ s
r c @ s e Zd ZdS )AlignedN)r r r r r r r r% ? s r% c @ s e Zd ZdZejdejdZdee e
eege
f dddZg dfeee
e e
e d d
dZeeeeef dd
dZeee eedddZeeeeedddZeeeedddZeeeeee dddZdS )EncodingVisualizera
Build an EncodingVisualizer
Args:
tokenizer (:class:`~tokenizers.Tokenizer`):
A tokenizer instance
default_to_notebook (:obj:`bool`):
Whether to render html output in a notebook by default
annotation_converter (:obj:`Callable`, `optional`):
An optional (lambda) function that takes an annotation in any format and returns
an Annotation object
z(.{1})?(unk|oov)(.{1})?)flagsTN) tokenizerdefault_to_notebookannotation_converterc C sZ |rDyddl m}m} W n* tk
rB } ztdW Y d d }~X nX || _|| _|| _d S )Nr )displayHTMLzWe couldn't import IPython utils for html display.
Are you running in a notebook?
You can also pass `default_to_notebook=False` to get back raw HTML
)IPython.core.displayr+ r, ImportError Exceptionr( r) annotation_coverter)r r( r) r* r+ r, er r r r V s zEncodingVisualizer.__init__)textannotationsr) r" c
C s | j }|dk r|}|rVyddlm}m} W n* tk
rT } ztdW Y dd}~X nX | jdk rptt| j|}| j j
|}tj|||} |r||| n| S dS )a
Build a visualization of the given text
Args:
text (:obj:`str`):
The text to tokenize
annotations (:obj:`List[Annotation]`, `optional`):
An optional list of annotations of the text. The can either be an annotation class
or anything else if you instantiated the visualizer with a converter function
default_to_notebook (:obj:`bool`, `optional`, defaults to `False`):
If True, will render the html in a notebook. Otherwise returns an html string.
Returns:
The HTML string if default_to_notebook is False, otherwise (default) returns None and
renders the HTML in the notebook
Nr )r+ r, zeWe couldn't import IPython utils for html display.
Are you running in a notebook?)
r) r- r+ r, r. r/ r0 listmapr( encoder&