o
    iN                     @   sf  d dl Z d dlZd dlmZ d dlmZmZmZmZ d dl	Z	d dl
mZ ddlmZ ddlmZ ddlmZ d	d
lmZmZmZmZmZmZmZ ejdddddedddddeddddddedddddeddddddedd d!d"dfd#e	jd$ed%ee d&ee d'ed(efd)d*Z	d.de  d+d$ee!ef d%eee!ef  d(ed,ee!ef fd-dZdS )/    N)Path)AnyDictOptionalUnion)msg   )util)init_nlp)train   )ArgOptappimport_codeparse_config_overrides	setup_gpushow_validation_errorr   T)allow_extra_argsignore_unknown_options)context_settings.zPath to config file)helpexists
allow_dashz--outputz--output-pathz-oz-Output directory to store trained pipeline in)r   z--codez-czNPath to Python file with additional code (registered functions) to be importedFz	--verbosez-Vz-VVz/Display more information for debugging purposesz--gpu-idz-gzGPU ID or -1 for CPUctxconfig_pathoutput_path	code_pathverboseuse_gpuc                 C   s8   |r	t jtj t| j}t| t||||d dS )a  
    Train or update a spaCy pipeline. Requires data in spaCy's binary format. To
    convert data from other formats, use the `spacy convert` command. The
    config file includes all settings and hyperparameters used during training.
    To override settings in the config, e.g. settings that point to local
    paths or that you want to experiment with, you can override them as
    command line options. For instance, --training.batch_size 128 overrides
    the value of "batch_size" in the block "[training]". The --code argument
    lets you pass in a Python file that's imported before training. It can be
    used to register custom functions and architectures that can then be
    referenced in the config.

    DOCS: https://spacy.io/api/cli#train
    r    	overridesN)	r	   loggersetLevelloggingDEBUGr   argsr   r   )r   r   r   r   r   r    r"    r(   C/home/ubuntu/.local/lib/python3.10/site-packages/spacy/cli/train.py	train_cli   s
   
r*   r!   r"   c                C   s0  t | } t |}| rt| dkr|  stjd| dd |s&td n| s8|jdd td|  td	|  t	| t
|  t j| |d
d}W d    n1 s[w   Y  td t
| d
d t||d}W d    n1 s|w   Y  td td t|||tjtjd d S )N-zConfig file not foundr   )exitszNo output directory providedT)parentszCreated output directory: zSaving to output directory: F)r"   interpolatezInitializing pipeline)	hint_fill)r    zInitialized pipelinezTraining pipeline)r    stdoutstderr)r	   ensure_pathstrr   r   failinfomkdirgoodr   r   load_configdividerr
   	train_nlpsysr0   r1   )r   r   r    r"   confignlpr(   r(   r)   r   9   s*   





)N)"r%   r;   pathlibr   typingr   r   r   r   typerwasabir    r	   training.initializer
   training.loopr   r:   _utilr   r   r   r   r   r   r   commandContextboolintr*   SimpleFrozenDictr3   r(   r(   r(   r)   <module>   sX    $
!

