/usr/local/lib/python3.6/site-packages/transformers/commands/__pycache__
Edit: /usr/local/lib/python3.6/site-packages/transformers/commands/__pycache__/run.cpython-36.pyc (3372B)
3
Eg @ sp d dl mZ ddlmZmZmZmZ ddlmZ ddl m
Z
ejeZ
eddd Zd
d ZG dd
d
e
ZdS ) )ArgumentParser )PipelinePipelineDataFormatget_supported_taskspipeline)logging )BaseTransformersCLICommand)pathc C s@ | sdS xt jD ]}| j|r|S qW td| dt j d S )Npipez4Unable to determine file format from file extension z-. Please provide the format through --format )r SUPPORTED_FORMATSendswith Exception)r ext r C/usr/local/lib/python3.6/site-packages/transformers/commands/run.pytry_infer_format_from_ext s
r c C sr t | j| jr| jnd | j| j| jd}| jdkr:t| jn| j}t j
|| j| j| jrZ| jn|j
| jd}t||S )N)taskmodelconfig tokenizerdeviceinfer)formatZoutput_pathZ
input_pathcolumn overwrite)r r r r r r r r inputr Zfrom_stroutputr Zdefault_input_namesr
RunCommand)argsnlpr readerr r r run_command_factory' s
r# c @ s6 e Zd ZeedddZeedddZdd Z d S )
r )r! r" c C s || _ || _d S )N)_nlp_reader)selfr! r" r r r __init__; s zRunCommand.__init__)parserc C s | j ddd}|jdt dd |jdtdd |jd
tdd |jdtd
d |jdtdd |jdtdd |jdtdd |jdtdtjdd |jdtd!dd |jdddd |jtd d S )"NrunzRun a pipeline through the CLI)helpz--taskzTask to run)choicesr* z--inputz%Path to the file to use for inference)typer* z--outputz9Path to the file that will be used post to write results.z--modelz)Name or path to the model to instantiate.z--configz2Name or path to the model's config to instantiate.z--tokenizerz?Name of the tokenizer to use. (default: same as the model name)z--columnzXName of the column to use as input. (For multi columns input as QA use column1,columns2)z--formatr zInput format to read from)r, defaultr+ r* z--devicer zSIndicate the device to run onto, -1 indicates CPU, >= 0 indicates GPU (default: -1))r, r- r* z--overwrite
store_truez"Allow overwriting the output file.)actionr* )func)
add_parseradd_argumentr strr r
intset_defaultsr# )r( Z
run_parserr r r register_subcommand? s2 zRunCommand.register_subcommandc C s | j g }}xF| jD ]<}| jjr*|f |n||}t|trH|j| q||7 }qW | j jrz| jj|}tj d| n| jj
| d S )NzCCurrent pipeline requires output to be in binary format, saving at )r$ r% Zis_multi_columns
isinstancedictappendZ
binary_outputZsave_binaryloggerwarningsave)r&