I'm trying to use Allennlp's Predictor for Correference Resolution. It works fine in Google Colab, but altough the dependencies are identical it throws an error when I tried the same code in my local. Here is the full error log and my code:
from allennlp.predictors.predictor import Predictor
model_url = 'https://storage.googleapis.com/allennlp-public-models/coref-spanbert-large-2020.02.27.tar.gz'
predictor = Predictor.from_path("../coref-spanbert-large-2020.02.27.tar.gz")
The errors below don't give too much detail about the problem. I even tried to download the model and to give its path. It didn't work also. I think Predictor object is the problem here.
KeyError Traceback (most recent call last)
File ~/anaconda3/envs/corr/lib/python3.8/site-packages/traitlets/traitlets.py:653, in TraitType.get(self, obj, cls)
652 try:
--> 653 value = obj._trait_values[self.name]
654 except KeyError:
655 # Check for a dynamic initializer.
KeyError: 'layout'
During handling of the above exception, another exception occurred:
NotImplementedError Traceback (most recent call last)
Input In [4], in <cell line: 2>()
1 # model_url = 'https://storage.googleapis.com/allennlp-public-models/coref-spanbert-large-2020.02.27.tar.gz'
----> 2 predictor = Predictor.from_path("../coref-spanbert-large-2020.02.27.tar.gz")
File ~/anaconda3/envs/corr/lib/python3.8/site-packages/allennlp/predictors/predictor.py:366, in Predictor.from_path(cls, archive_path, predictor_name, cuda_device, dataset_reader_to_load, frozen, import_plugins, overrides, **kwargs)
363 if import_plugins:
364 plugins.import_plugins()
365 return Predictor.from_archive(
--> 366 load_archive(archive_path, cuda_device=cuda_device, overrides=overrides),
367 predictor_name,
368 dataset_reader_to_load=dataset_reader_to_load,
369 frozen=frozen,
370 extra_args=kwargs,
371 )
File ~/anaconda3/envs/corr/lib/python3.8/site-packages/allennlp/models/archival.py:232, in load_archive(archive_file, cuda_device, overrides, weights_file)
229 config = Params.from_file(os.path.join(serialization_dir, CONFIG_NAME), overrides)
231 # Instantiate model and dataset readers. Use a duplicate of the config, as it will get consumed.
--> 232 dataset_reader, validation_dataset_reader = _load_dataset_readers(
233 config.duplicate(), serialization_dir
234 )
235 model = _load_model(config.duplicate(), weights_path, serialization_dir, cuda_device)
237 # Load meta.
File ~/anaconda3/envs/corr/lib/python3.8/site-packages/allennlp/models/archival.py:268, in _load_dataset_readers(config, serialization_dir)
262 # Try to use the validation dataset reader if there is one - otherwise fall back
263 # to the default dataset_reader used for both training and validation.
264 validation_dataset_reader_params = config.get(
265 "validation_dataset_reader", dataset_reader_params.duplicate()
266 )
--> 268 dataset_reader = DatasetReader.from_params(
269 dataset_reader_params, serialization_dir=serialization_dir
270 )
271 validation_dataset_reader = DatasetReader.from_params(
272 validation_dataset_reader_params, serialization_dir=serialization_dir
273 )
275 return dataset_reader, validation_dataset_reader
File ~/anaconda3/envs/corr/lib/python3.8/site-packages/allennlp/common/from_params.py:604, in FromParams.from_params(cls, params, constructor_to_call, constructor_to_inspect, **extras)
602 # mypy can't follow the typing redirection that we do, so we explicitly cast here.
603 retyped_subclass = cast(Type[T], subclass)
--> 604 return retyped_subclass.from_params(
605 params=params,
606 constructor_to_call=constructor_to_call,
607 constructor_to_inspect=constructor_to_inspect,
608 **extras,
609 )
610 else:
611 # In some rare cases, we get a registered subclass that does _not_ have a
612 # from_params method (this happens with Activations, for instance, where we
(...)
615 # you've done the right thing in passing your parameters, and nothing else needs to
616 # be recursively constructed.
617 return subclass(**params) # type: ignore
File ~/anaconda3/envs/corr/lib/python3.8/site-packages/allennlp/common/from_params.py:636, in FromParams.from_params(cls, params, constructor_to_call, constructor_to_inspect, **extras)
633 else:
634 # This class has a constructor, so create kwargs for it.
635 constructor_to_inspect = cast(Callable[..., T], constructor_to_inspect)
--> 636 kwargs = create_kwargs(constructor_to_inspect, cls, params, **extras)
638 return constructor_to_call(**kwargs)
File ~/anaconda3/envs/corr/lib/python3.8/site-packages/allennlp/common/from_params.py:206, in create_kwargs(constructor, cls, params, **extras)
203 annotation = remove_optional(param.annotation)
205 explicitly_set = param_name in params
--> 206 constructed_arg = pop_and_construct_arg(
207 cls.__name__, param_name, annotation, param.default, params, **extras
208 )
210 # If the param wasn't explicitly set in `params` and we just ended up constructing
211 # the default value for the parameter, we can just omit it.
212 # Leaving it in can cause issues with **kwargs in some corner cases, where you might end up
213 # with multiple values for a single parameter (e.g., the default value gives you lazy=False
214 # for a dataset reader inside **kwargs, but a particular dataset reader actually hard-codes
215 # lazy=True - the superclass sees both lazy=True and lazy=False in its constructor).
216 if explicitly_set or constructed_arg is not param.default:
File ~/anaconda3/envs/corr/lib/python3.8/site-packages/allennlp/common/from_params.py:314, in pop_and_construct_arg(class_name, argument_name, annotation, default, params, **extras)
311 if popped_params is None:
312 return None
--> 314 return construct_arg(class_name, name, popped_params, annotation, default, **extras)
File ~/anaconda3/envs/corr/lib/python3.8/site-packages/allennlp/common/from_params.py:394, in construct_arg(class_name, argument_name, popped_params, annotation, default, **extras)
389 raise TypeError(
390 f"Expected {argument_name} to be a Mapping (probably a dict or a Params object)."
391 )
393 for key, value_params in popped_params.items():
--> 394 value_dict[key] = construct_arg(
395 str(value_cls),
396 argument_name + "." + key,
397 value_params,
398 value_cls,
399 _NO_DEFAULT,
400 **extras,
401 )
403 return value_dict
405 elif origin in (Tuple, tuple) and all(can_construct_from_params(arg) for arg in args):
File ~/anaconda3/envs/corr/lib/python3.8/site-packages/allennlp/common/from_params.py:348, in construct_arg(class_name, argument_name, popped_params, annotation, default, **extras)
346 elif isinstance(popped_params, dict):
347 popped_params = Params(popped_params)
--> 348 result = annotation.from_params(params=popped_params, **subextras)
350 return result
351 elif not optional:
352 # Not optional and not supplied, that's an error!
File ~/anaconda3/envs/corr/lib/python3.8/site-packages/allennlp/common/from_params.py:604, in FromParams.from_params(cls, params, constructor_to_call, constructor_to_inspect, **extras)
602 # mypy can't follow the typing redirection that we do, so we explicitly cast here.
603 retyped_subclass = cast(Type[T], subclass)
--> 604 return retyped_subclass.from_params(
605 params=params,
606 constructor_to_call=constructor_to_call,
607 constructor_to_inspect=constructor_to_inspect,
608 **extras,
609 )
610 else:
611 # In some rare cases, we get a registered subclass that does _not_ have a
612 # from_params method (this happens with Activations, for instance, where we
(...)
615 # you've done the right thing in passing your parameters, and nothing else needs to
616 # be recursively constructed.
617 return subclass(**params) # type: ignore
File ~/anaconda3/envs/corr/lib/python3.8/site-packages/allennlp/common/from_params.py:638, in FromParams.from_params(cls, params, constructor_to_call, constructor_to_inspect, **extras)
635 constructor_to_inspect = cast(Callable[..., T], constructor_to_inspect)
636 kwargs = create_kwargs(constructor_to_inspect, cls, params, **extras)
--> 638 return constructor_to_call(**kwargs)
File ~/anaconda3/envs/corr/lib/python3.8/site-packages/allennlp/data/token_indexers/pretrained_transformer_mismatched_indexer.py:58, in PretrainedTransformerMismatchedIndexer.__init__(self, model_name, namespace, max_length, tokenizer_kwargs, **kwargs)
56 super().__init__(**kwargs)
57 # The matched version v.s. mismatched
---> 58 self._matched_indexer = PretrainedTransformerIndexer(
59 model_name,
60 namespace=namespace,
61 max_length=max_length,
62 tokenizer_kwargs=tokenizer_kwargs,
63 **kwargs,
64 )
65 self._allennlp_tokenizer = self._matched_indexer._allennlp_tokenizer
66 self._tokenizer = self._matched_indexer._tokenizer
File ~/anaconda3/envs/corr/lib/python3.8/site-packages/allennlp/data/token_indexers/pretrained_transformer_indexer.py:56, in PretrainedTransformerIndexer.__init__(self, model_name, namespace, max_length, tokenizer_kwargs, **kwargs)
54 super().__init__(**kwargs)
55 self._namespace = namespace
---> 56 self._allennlp_tokenizer = PretrainedTransformerTokenizer(
57 model_name, tokenizer_kwargs=tokenizer_kwargs
58 )
59 self._tokenizer = self._allennlp_tokenizer.tokenizer
60 self._added_to_vocabulary = False
File ~/anaconda3/envs/corr/lib/python3.8/site-packages/allennlp/data/tokenizers/pretrained_transformer_tokenizer.py:72, in PretrainedTransformerTokenizer.__init__(self, model_name, add_special_tokens, max_length, tokenizer_kwargs, verification_tokens)
68 self._model_name = model_name
70 from allennlp.common import cached_transformers
---> 72 self.tokenizer = cached_transformers.get_tokenizer(
73 self._model_name, add_special_tokens=False, **self._tokenizer_kwargs
74 )
76 self._add_special_tokens = add_special_tokens
77 self._max_length = max_length
File ~/anaconda3/envs/corr/lib/python3.8/site-packages/allennlp/common/cached_transformers.py:204, in get_tokenizer(model_name, **kwargs)
202 tokenizer = _tokenizer_cache.get(cache_key, None)
203 if tokenizer is None:
--> 204 tokenizer = transformers.AutoTokenizer.from_pretrained(
205 model_name,
206 **kwargs,
207 )
208 _tokenizer_cache[cache_key] = tokenizer
209 return tokenizer
File ~/anaconda3/envs/corr/lib/python3.8/site-packages/transformers/models/auto/tokenization_auto.py:535, in AutoTokenizer.from_pretrained(cls, pretrained_model_name_or_path, *inputs, **kwargs)
533 if config_tokenizer_class is None:
534 if not isinstance(config, PretrainedConfig):
--> 535 config = AutoConfig.from_pretrained(
536 pretrained_model_name_or_path, trust_remote_code=trust_remote_code, **kwargs
537 )
538 config_tokenizer_class = config.tokenizer_class
539 if hasattr(config, "auto_map") and "AutoTokenizer" in config.auto_map:
File ~/anaconda3/envs/corr/lib/python3.8/site-packages/transformers/models/auto/configuration_auto.py:705, in AutoConfig.from_pretrained(cls, pretrained_model_name_or_path, **kwargs)
703 kwargs["name_or_path"] = pretrained_model_name_or_path
704 trust_remote_code = kwargs.pop("trust_remote_code", False)
--> 705 config_dict, _ = PretrainedConfig.get_config_dict(pretrained_model_name_or_path, **kwargs)
706 if "auto_map" in config_dict and "AutoConfig" in config_dict["auto_map"]:
707 if not trust_remote_code:
File ~/anaconda3/envs/corr/lib/python3.8/site-packages/transformers/configuration_utils.py:553, in PretrainedConfig.get_config_dict(cls, pretrained_model_name_or_path, **kwargs)
551 original_kwargs = copy.deepcopy(kwargs)
552 # Get config dict associated with the base config file
--> 553 config_dict, kwargs = cls._get_config_dict(pretrained_model_name_or_path, **kwargs)
555 # That config file may point us toward another config file to use.
556 if "configuration_files" in config_dict:
File ~/anaconda3/envs/corr/lib/python3.8/site-packages/transformers/configuration_utils.py:601, in PretrainedConfig._get_config_dict(cls, pretrained_model_name_or_path, **kwargs)
595 config_file = hf_bucket_url(
596 pretrained_model_name_or_path, filename=configuration_file, revision=revision, mirror=None
597 )
599 try:
600 # Load from URL or cache if already cached
--> 601 resolved_config_file = cached_path(
602 config_file,
603 cache_dir=cache_dir,
604 force_download=force_download,
605 proxies=proxies,
606 resume_download=resume_download,
607 local_files_only=local_files_only,
608 use_auth_token=use_auth_token,
609 user_agent=user_agent,
610 )
612 except RepositoryNotFoundError:
613 raise EnvironmentError(
614 f"{pretrained_model_name_or_path} is not a local folder and is not a valid model identifier listed on "
615 "'https://huggingface.co/models'\nIf this is a private repository, make sure to pass a token having "
616 "permission to this repo with `use_auth_token` or log in with `huggingface-cli login` and pass "
617 "`use_auth_token=True`."
618 )
File ~/anaconda3/envs/corr/lib/python3.8/site-packages/transformers/utils/hub.py:284, in cached_path(url_or_filename, cache_dir, force_download, proxies, resume_download, user_agent, extract_compressed_file, force_extract, use_auth_token, local_files_only)
280 local_files_only = True
282 if is_remote_url(url_or_filename):
283 # URL, so get it from the cache (downloading if necessary)
--> 284 output_path = get_from_cache(
285 url_or_filename,
286 cache_dir=cache_dir,
287 force_download=force_download,
288 proxies=proxies,
289 resume_download=resume_download,
290 user_agent=user_agent,
291 use_auth_token=use_auth_token,
292 local_files_only=local_files_only,
293 )
294 elif os.path.exists(url_or_filename):
295 # File, and it exists.
296 output_path = url_or_filename
File ~/anaconda3/envs/corr/lib/python3.8/site-packages/transformers/utils/hub.py:594, in get_from_cache(url, cache_dir, force_download, proxies, etag_timeout, resume_download, user_agent, use_auth_token, local_files_only)
591 with temp_file_manager() as temp_file:
592 logger.info(f"{url} not found in cache or force_download set to True, downloading to {temp_file.name}")
--> 594 http_get(url_to_download, temp_file, proxies=proxies, resume_size=resume_size, headers=headers)
596 logger.info(f"storing {url} in cache at {cache_path}")
597 os.replace(temp_file.name, cache_path)
File ~/anaconda3/envs/corr/lib/python3.8/site-packages/transformers/utils/hub.py:438, in http_get(url, temp_file, proxies, resume_size, headers)
435 total = resume_size + int(content_length) if content_length is not None else None
436 # `tqdm` behavior is determined by `utils.logging.is_progress_bar_enabled()`
437 # and can be set using `utils.logging.enable/disable_progress_bar()`
--> 438 progress = tqdm(
439 unit="B",
440 unit_scale=True,
441 unit_divisor=1024,
442 total=total,
443 initial=resume_size,
444 desc="Downloading",
445 )
446 for chunk in r.iter_content(chunk_size=1024):
447 if chunk: # filter out keep-alive new chunks
File ~/anaconda3/envs/corr/lib/python3.8/site-packages/transformers/utils/logging.py:312, in _tqdm_cls.__call__(self, *args, **kwargs)
310 def __call__(self, *args, **kwargs):
311 if _tqdm_active:
--> 312 return tqdm_lib.tqdm(*args, **kwargs)
313 else:
314 return EmptyTqdm(*args, **kwargs)
File ~/.local/lib/python3.8/site-packages/tqdm/notebook.py:242, in tqdm_notebook.__init__(self, *args, **kwargs)
240 unit_scale = 1 if self.unit_scale is True else self.unit_scale or 1
241 total = self.total * unit_scale if self.total else self.total
--> 242 self.container = self.status_printer(self.fp, total, self.desc, self.ncols)
243 self.container.pbar = proxy(self)
244 self.displayed = False
File ~/.local/lib/python3.8/site-packages/tqdm/notebook.py:120, in tqdm_notebook.status_printer(_, total, desc, ncols)
118 raise ImportError(WARN_NOIPYW)
119 if total:
--> 120 pbar = IProgress(min=0, max=total)
121 else: # No total? Show info style bar with no progress tqdm status
122 pbar = IProgress(min=0, max=1)
File ~/anaconda3/envs/corr/lib/python3.8/site-packages/ipywidgets/widgets/widget_float.py:26, in _Float.__init__(self, value, **kwargs)
24 if value is not None:
25 kwargs['value'] = value
---> 26 super().__init__(**kwargs)
File ~/anaconda3/envs/corr/lib/python3.8/site-packages/ipywidgets/widgets/widget_description.py:35, in DescriptionWidget.__init__(self, *args, **kwargs)
33 kwargs.setdefault('tooltip', kwargs['description_tooltip'])
34 del kwargs['description_tooltip']
---> 35 super().__init__(*args, **kwargs)
File ~/anaconda3/envs/corr/lib/python3.8/site-packages/ipywidgets/widgets/widget.py:504, in Widget.__init__(self, **kwargs)
501 super().__init__(**kwargs)
503 Widget._call_widget_constructed(self)
--> 504 self.open()
File ~/anaconda3/envs/corr/lib/python3.8/site-packages/ipywidgets/widgets/widget.py:517, in Widget.open(self)
515 """Open a comm to the frontend if one isn't already open."""
516 if self.comm is None:
--> 517 state, buffer_paths, buffers = _remove_buffers(self.get_state())
519 args = dict(target_name='jupyter.widget',
520 data={'state': state, 'buffer_paths': buffer_paths},
521 buffers=buffers,
522 metadata={'version': __protocol_version__}
523 )
524 if self._model_id is not None:
File ~/anaconda3/envs/corr/lib/python3.8/site-packages/ipywidgets/widgets/widget.py:615, in Widget.get_state(self, key, drop_defaults)
613 for k in keys:
614 to_json = self.trait_metadata(k, 'to_json', self._trait_to_json)
--> 615 value = to_json(getattr(self, k), self)
616 if not drop_defaults or not self._compare(value, traits[k].default_value):
617 state[k] = value
File ~/anaconda3/envs/corr/lib/python3.8/site-packages/traitlets/traitlets.py:700, in TraitType.__get__(self, obj, cls)
698 return self
699 else:
--> 700 return self.get(obj, cls)
File ~/anaconda3/envs/corr/lib/python3.8/site-packages/traitlets/traitlets.py:656, in TraitType.get(self, obj, cls)
653 value = obj._trait_values[self.name]
654 except KeyError:
655 # Check for a dynamic initializer.
--> 656 default = obj.trait_defaults(self.name)
657 if default is Undefined:
658 warn(
659 "Explicit using of Undefined as the default value "
660 "is deprecated in traitlets 5.0, and may cause "
(...)
663 stacklevel=2,
664 )
File ~/anaconda3/envs/corr/lib/python3.8/site-packages/traitlets/traitlets.py:1868, in HasTraits.trait_defaults(self, *names, **metadata)
1865 raise TraitError(f"'{n}' is not a trait of '{type(self).__name__}' instances")
1867 if len(names) == 1 and len(metadata) == 0:
-> 1868 return self._get_trait_default_generator(names[0])(self)
1870 trait_names = self.trait_names(**metadata)
1871 trait_names.extend(names)
File ~/anaconda3/envs/corr/lib/python3.8/site-packages/traitlets/traitlets.py:624, in TraitType.default(self, obj)
622 return self.default_value
623 elif hasattr(self, "make_dynamic_default"):
--> 624 return self.make_dynamic_default()
625 else:
626 # Undefined will raise in TraitType.get
627 return self.default_value
File ~/anaconda3/envs/corr/lib/python3.8/site-packages/ipywidgets/widgets/trait_types.py:365, in InstanceDict.make_dynamic_default(self)
364 def make_dynamic_default(self):
--> 365 return self.klass(*(self.default_args or ()),
366 **(self.default_kwargs or {}))
File ~/anaconda3/envs/corr/lib/python3.8/site-packages/ipywidgets/widgets/widget_layout.py:86, in Layout.__init__(self, **kwargs)
83 for side in ['top', 'right', 'bottom', 'left']:
84 kwargs.setdefault(f'border_{side}', border)
---> 86 super().__init__(**kwargs)
File ~/anaconda3/envs/corr/lib/python3.8/site-packages/ipywidgets/widgets/widget.py:504, in Widget.__init__(self, **kwargs)
501 super().__init__(**kwargs)
503 Widget._call_widget_constructed(self)
--> 504 self.open()
File ~/anaconda3/envs/corr/lib/python3.8/site-packages/ipywidgets/widgets/widget.py:535, in Widget.open(self)
531 from ipykernel.comm import Comm
533 return Comm(**kwargs)
--> 535 self.comm = create_comm(**args)
File ~/anaconda3/envs/corr/lib/python3.8/site-packages/comm/__init__.py:27, in _create_comm(*args, **kwargs)
22 def _create_comm(*args, **kwargs):
23 """Create a Comm.
24
25 This method is intended to be replaced, so that it returns your Comm instance.
26 """
---> 27 raise NotImplementedError("Cannot ")
NotImplementedError: Cannot
I need to use this library, and I can't fix it. What am I missing here ?