@@ -158,7 +158,7 @@ class CardData:
158158 inherit from `dict` to allow this export step.
159159 """
160160
161- def __init__ (self , ** kwargs ):
161+ def __init__ (self , ignore_metadata_errors : bool = False , ** kwargs ):
162162 self .__dict__ .update (kwargs )
163163
164164 def to_dict (self ) -> Dict [str , Any ]:
@@ -248,6 +248,9 @@ class ModelCardData(CardData):
248248 `eval_results` to construct the `model-index` within the card's metadata. The name
249249 you supply here is what will be used on PapersWithCode's leaderboards. If None is provided
250250 then the repo name is used as a default. Defaults to None.
251+ ignore_metadata_errors (`str`):
252+ If True, errors while parsing the metadata section will be ignored. Some information might be lost during
253+ the process. Use it at your own risk.
251254 kwargs (`dict`, *optional*):
252255 Additional metadata that will be added to the model card. Defaults to None.
253256
@@ -277,6 +280,7 @@ def __init__(
277280 metrics : Optional [List [str ]] = None ,
278281 eval_results : Optional [List [EvalResult ]] = None ,
279282 model_name : Optional [str ] = None ,
283+ ignore_metadata_errors : bool = False ,
280284 ** kwargs ,
281285 ):
282286 self .language = language
@@ -294,8 +298,15 @@ def __init__(
294298 model_name , eval_results = model_index_to_eval_results (model_index )
295299 self .model_name = model_name
296300 self .eval_results = eval_results
297- except KeyError :
298- logger .warning ("Invalid model-index. Not loading eval results into CardData." )
301+ except KeyError as error :
302+ if ignore_metadata_errors :
303+ logger .warning ("Invalid model-index. Not loading eval results into CardData." )
304+ else :
305+ raise ValueError (
306+ f"Invalid `model_index` in metadata cannot be parsed: KeyError { error } . Pass"
307+ " `ignore_metadata_errors=True` to ignore this error while loading a Model Card. Warning:"
308+ " some information will be lost. Use it at your own risk."
309+ )
299310
300311 super ().__init__ (** kwargs )
301312
@@ -350,6 +361,9 @@ class DatasetCardData(CardData):
350361 If not provided, it will be gathered from the 'train-eval-index' key of the kwargs.
351362 configs (`Union[str, List[str]]`, *optional*):
352363 A list of the available dataset configs for the dataset.
364+ ignore_metadata_errors (`str`):
365+ If True, errors while parsing the metadata section will be ignored. Some information might be lost during
366+ the process. Use it at your own risk.
353367 """
354368
355369 def __init__ (
@@ -368,6 +382,7 @@ def __init__(
368382 pretty_name : Optional [str ] = None ,
369383 train_eval_index : Optional [Dict ] = None ,
370384 configs : Optional [Union [str , List [str ]]] = None ,
385+ ignore_metadata_errors : bool = False ,
371386 ** kwargs ,
372387 ):
373388 self .annotations_creators = annotations_creators
@@ -421,6 +436,9 @@ class SpaceCardData(CardData):
421436 List of datasets related to this Space. Should be a dataset ID found on https://hf.co/datasets.
422437 tags (`List[str]`, *optional*)
423438 List of tags to add to your Space that can be used when filtering on the Hub.
439+ ignore_metadata_errors (`str`):
440+ If True, errors while parsing the metadata section will be ignored. Some information might be lost during
441+ the process. Use it at your own risk.
424442 kwargs (`dict`, *optional*):
425443 Additional metadata that will be added to the space card.
426444
@@ -452,6 +470,7 @@ def __init__(
452470 models : Optional [List [str ]] = None ,
453471 datasets : Optional [List [str ]] = None ,
454472 tags : Optional [List [str ]] = None ,
473+ ignore_metadata_errors : bool = False ,
455474 ** kwargs ,
456475 ):
457476 self .title = title
0 commit comments