예제 #1
0
    def __init__(self,
                 func: callable,
                 annotations: dict,
                 strict: bool = True,
                 wrap: (bool, callable) = False,
                 name: str = None,
                 desc: str = None):
        self.func = func
        self.annotations = ann = self.make_annotations(annotations)
        if strict:
            self.plac_func = plac.annotations(**ann)(func)
        else:
            self.plac_func = plac_annotations(wrap, **ann)(func)

        if name is None:
            name = func.__name__
        self.name = name

        if desc is None:
            if func.__doc__ is not None and func.__doc__:
                desc = func.__doc__
            else:
                desc = f'command `{name}` (no description)'
        self.desc = desc
        self.plac_func.__doc__ = desc
예제 #2
0
def annotate(*args, **kwargs):
    '''Return a decorator for plac-style argument annotations.'''
    return plac.annotations(*args, **kwargs)
예제 #3
0
    d={}
    for item in patterns.A.iter(x):
        val=((item[0]-len(item[1][1]))+1,item[0]+1,item[1][0])
        list_ent.append(val)
    d["entities"]=list_ent
    TRAIN_DATA.append((x,d)


df_test=pd.read_csv('/Users/pragnyasuresh/Desktop/team_no_8/test_ner.csv')
test=df_test["review"]
TEST_DATA=list(test)


@plac.annotations(
                  model=("Model name. Defaults to blank 'en' model.", "option", "m", str),
                  output_dir=("/Users/pragnyasuresh/Desktop/team_no_8", "option", "o", Path),
                  n_iter=("Number of training iterations", "option", "n", int),
                  )
def main(model=None, output_dir="/Users/pragnyasuresh/Desktop/team_no_8", n_iter=100):
    """Load the model, set up the pipeline and train the entity recognizer."""
    if model is not None:
        nlp = spacy.load(model)  # load existing spaCy model
        print("Loaded model '%s'" % model)
    else:
        nlp = spacy.blank("en")  # create blank Language class
        print("Created blank 'en' model")
    
    # create the built-in pipeline components and add them to the pipeline
    # nlp.create_pipe works for built-ins that are registered with spaCy
    if "ner" not in nlp.pipe_names:
        ner = nlp.create_pipe("ner")
예제 #4
0
def overlap_tokens(doc, other_doc):
    """Get the tokens from the original Doc that are also in the comparison Doc.
    """
    overlap = []
    other_tokens = [token.text for token in other_doc]
    for token in doc:
        if token.text in other_tokens:
            overlap.append(token)
    return overlap


if __name__ == '__main__':
plac.call(main)

@plac.annotations(
    model=("Model name. Defaults to blank 'en' model.", "option", "m", str),
    output_dir=("Optional output directory", "option", "o", Path),
    n_iter=("Number of training iterations", "option", "n", int))
        def main(model=None, output_dir=None, n_iter=100):
    """Load the model, set up the pipeline and train the entity recognizer."""
    if model is not None:
        nlp = spacy.load(model)  # load existing spaCy model
        print("Loaded model '%s'" % model)
    else:
        nlp = spacy.blank('en')  # create blank Language class
        print("Created blank 'en' model")

    # create the built-in pipeline components and add them to the pipeline
    # nlp.create_pipe works for built-ins that are registered with spaCy
    if 'ner' not in nlp.pipe_names:
        ner = nlp.create_pipe('ner')
        nlp.add_pipe(ner, last=True)
예제 #5
0
파일: __init__.py 프로젝트: arg0/py-cli
def annotate(*args, **kwargs):
    '''Return a decorator for plac-style argument annotations.'''
    return plac.annotations(*args, **kwargs)