运行简单的变压器来测试NER会导致错误。有什么办法吗?

时间:2020-07-19 10:28:27

标签: python multiprocessing huggingface-transformers simpletransformers

我正在尝试使用简单的变压器测试此https://github.com/ThilinaRajapakse/simpletransformers#minimal-start NER,并遇到以下错误。有人可以指导我解决这个问题吗?

我尝试使用拥抱脸部变形器lib编写自己的NER,但仍然遇到相同的问题。

对此进行了尝试:https://github.com/ThilinaRajapakse/simpletransformers/issues/370#issuecomment-627763738仍然面对python3.7的相同问题

错误:

File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\site-packages\simpletransformers\ner\ner_model.py", line 242, in train_model
    train_dataset = self.load_and_cache_examples(train_data)
  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\site-packages\simpletransformers\ner\ner_model.py", line 986, in load_and_cache_examples
    features = convert_examples_to_features(
  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\site-packages\simpletransformers\ner\ner_utils.py", line 242, in convert_examples_to_features
    with Pool(process_count) as p:
  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\multiprocessing\context.py", line 119, in Pool
    return Pool(processes, initializer, initargs, maxtasksperchild,
INFO:simpletransformers.ner.ner_model: Converting to features started.
  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\multiprocessing\pool.py", line 212, in __init__
Traceback (most recent call last):
    self._repopulate_pool()
  File "<string>", line 1, in <module>
  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\multiprocessing\pool.py", line 303, in _repopulate_pool
  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\multiprocessing\spawn.py", line 116, in spawn_main
    return self._repopulate_pool_static(self._ctx, self.Process,
    exitcode = _main(fd, parent_sentinel)
  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\multiprocessing\spawn.py", line 125, in _main
  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\multiprocessing\pool.py", line 326, in _repopulate_pool_static
    prepare(preparation_data)
  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\multiprocessing\spawn.py", line 236, in prepare
    w.start()
  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\multiprocessing\process.py", line 121, in start
    self._popen = self._Popen(self)
    _fixup_main_from_path(data['init_main_from_path'])
  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\multiprocessing\spawn.py", line 287, in _fixup_main_from_path
  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\multiprocessing\context.py", line 326, in _Popen
    main_content = runpy.run_path(main_path,
    return Popen(process_obj)
  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\runpy.py", line 265, in run_path
  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\multiprocessing\popen_spawn_win32.py", line 45, in __init__
    prep_data = spawn.get_preparation_data(process_obj._name)
    return _run_module_code(code, init_globals, run_name,
  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\multiprocessing\spawn.py", line 154, in get_preparation_data
  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\runpy.py", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
    _check_not_importing_main()
  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\runpy.py", line 87, in _run_code
  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\multiprocessing\spawn.py", line 134, in _check_not_importing_main
    exec(code, run_globals)
    raise RuntimeError('''
  File "C:\Users\Harsha\Desktop\git_repos\bert-ner\src\inference_ner_simple_transformers.py", line 27, in <module>
RuntimeError:
        An attempt has been made to start a new process before the
        current process has finished its bootstrapping phase.

        This probably means that you are not using fork to start your
        child processes and you have forgotten to use the proper idiom
        in the main module:

            if __name__ == '__main__':
                freeze_support()
                ...

        The "freeze_support()" line can be omitted if the program
        is not going to be frozen to produce an executable.    model.train_model(train_df)

  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\site-packages\simpletransformers\ner\ner_model.py", line 242, in train_model
    train_dataset = self.load_and_cache_examples(train_data)
  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\site-packages\simpletransformers\ner\ner_model.py", line 986, in load_and_cache_examples
INFO:simpletransformers.ner.ner_model: Converting to features started.
    features = convert_examples_to_features(
  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\site-packages\simpletransformers\ner\ner_utils.py", line 242, in convert_examples_to_features
Traceback (most recent call last):
    with Pool(process_count) as p:
INFO:simpletransformers.ner.ner_model: Converting to features started.
  File "<string>", line 1, in <module>
  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\multiprocessing\context.py", line 119, in Pool
  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\multiprocessing\spawn.py", line 116, in spawn_main
Traceback (most recent call last):
  File "<string>", line 1, in <module>
    return Pool(processes, initializer, initargs, maxtasksperchild,
  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\multiprocessing\pool.py", line 212, in __init__
    exitcode = _main(fd, parent_sentinel)
  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\multiprocessing\spawn.py", line 125, in _main
  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\multiprocessing\spawn.py", line 116, in spawn_main
    self._repopulate_pool()
  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\multiprocessing\pool.py", line 303, in _repopulate_pool
    prepare(preparation_data)
    exitcode = _main(fd, parent_sentinel)
    return self._repopulate_pool_static(self._ctx, self.Process,
  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\multiprocessing\spawn.py", line 236, in prepare
  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\multiprocessing\spawn.py", line 125, in _main
  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\multiprocessing\pool.py", line 326, in _repopulate_pool_static
    _fixup_main_from_path(data['init_main_from_path'])
  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\multiprocessing\spawn.py", line 287, in _fixup_main_from_path
    w.start()
    prepare(preparation_data)
INFO:simpletransformers.ner.ner_model: Converting to features started.
  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\multiprocessing\process.py", line 121, in start
Traceback (most recent call last):
    main_content = runpy.run_path(main_path,
  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\multiprocessing\spawn.py", line 236, in prepare
    self._popen = self._Popen(self)
  File "<string>", line 1, in <module>
  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\runpy.py", line 265, in run_path
  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\multiprocessing\context.py", line 326, in _Popen
  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\multiprocessing\spawn.py", line 116, in spawn_main
    _fixup_main_from_path(data['init_main_from_path'])
    return _run_module_code(code, init_globals, run_name,
  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\multiprocessing\spawn.py", line 287, in _fixup_main_from_path
    return Popen(process_obj)
  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\runpy.py", line 97, in _run_module_code
    exitcode = _main(fd, parent_sentinel)
  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\multiprocessing\popen_spawn_win32.py", line 45, in __init__
  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\multiprocessing\spawn.py", line 125, in _main
    main_content = runpy.run_path(main_path,
    _run_code(code, mod_globals, init_globals,
  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\runpy.py", line 265, in run_path
  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\runpy.py", line 87, in _run_code
    prep_data = spawn.get_preparation_data(process_obj._name)
    prepare(preparation_data)
  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\multiprocessing\spawn.py", line 154, in get_preparation_data
  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\multiprocessing\spawn.py", line 236, in prepare
    return _run_module_code(code, init_globals, run_name,
    exec(code, run_globals)
  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\runpy.py", line 97, in _run_module_code
  File "C:\Users\Harsha\Desktop\git_repos\bert-ner\src\inference_ner_simple_transformers.py", line 27, in <module>
    _check_not_importing_main()
    _fixup_main_from_path(data['init_main_from_path'])
    _run_code(code, mod_globals, init_globals,
  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\multiprocessing\spawn.py", line 134, in _check_not_importing_main
    model.train_model(train_df)
  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\multiprocessing\spawn.py", line 287, in _fixup_main_from_path
  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\runpy.py", line 87, in _run_code
  File "C:\Users\Harsha\Anaconda3\envs\simpt\lib\site-packages\simpletransformers\ner\ner_model.py", line 242, in train_model

系统配置: Windows 10 GTX 1070 Python 3.8.3 变压器2.1.1 火炬1.5.1 康达环境 enter image description here

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,并通过以下方法解决了该问题:

model.train_model

在以下主要的if语句中:

if __name__ == '__main__':