Как выполнить вывод на моделях Huggingface NER - PullRequest
0 голосов
/ 29 мая 2020

Я обучил пользовательскую модель NER, используя библиотеку Huggingface. Код обучения: https://github.com/huggingface/transformers/tree/master/examples/token-classification

Вывод выполняется с использованием конвейера, который указывает на мою модель:

class BERTExtractor:
"""class BERTExtractor encapsulates logic to pipe Records with text body
through a BERT model and return entities separated by Entity Type
"""

def __init__(self, model_path):
    """Initialize the BERTExtractor pipeline.
    model_path: Path to the Bert language model
    RETURNS (EntityRecognizer): The newly constructed object.
    """
    # load the NER tagger
    self.model_prediction_pipeline = pipeline(
        "ner", model=model_path,
        # tokenizer=model_path,
        tokenizer=AutoTokenizer.from_pretrained('distilbert-base-cased'),
        grouped_entities=True
    )

Код вывода:

    async def extract_entities(
    self, input_text_list: List[str]
) -> List[RecordDataResponse]:
    """Apply the pre-trained model to a batch of records
    input_text (str): The input text which needs to be predicted
    RETURNS (list): List of responses containing the
    the correlating document and a list of entities.
    """

    # Normalize the sequences
    prediction_input_list = self._normalize_input_sequence_length(input_text_list)

    # Perform prediction
    prediction_results_list = [
        prediction
        for prediction_input in prediction_input_list
        for prediction in self.model_prediction_pipeline(prediction_input)
        if prediction
        and prediction["word"] not in self.stop_list
    ]

Пожалуйста, уточните следующие вопросы:

  1. Следует ли мне обучать настраиваемый токенизатор и создавать файл словаря перед логическим выводом ?
  2. Можем ли мы используя конвейер HuggingFace для вывода, или следует ли писать собственный сценарий для вывода после кодирования входного текста?

Спасибо.

...