MCPcopy Create free account
hub / github.com/SooLab/CGFormer / add_code_sample_docstrings

Function add_code_sample_docstrings

bert/file_utils.py:417–443  ·  view source on GitHub ↗
(*docstr, tokenizer_class=None, checkpoint=None)

Source from the content-addressed store, hash-verified

415
416
417def add_code_sample_docstrings(*docstr, tokenizer_class=None, checkpoint=None):
418 def docstring_decorator(fn):
419 model_class = fn.__qualname__.split(".")[0]
420 is_tf_class = model_class[:2] == "TF"
421
422 if "SequenceClassification" in model_class:
423 code_sample = TF_SEQUENCE_CLASSIFICATION_SAMPLE if is_tf_class else PT_SEQUENCE_CLASSIFICATION_SAMPLE
424 elif "QuestionAnswering" in model_class:
425 code_sample = TF_QUESTION_ANSWERING_SAMPLE if is_tf_class else PT_QUESTION_ANSWERING_SAMPLE
426 elif "TokenClassification" in model_class:
427 code_sample = TF_TOKEN_CLASSIFICATION_SAMPLE if is_tf_class else PT_TOKEN_CLASSIFICATION_SAMPLE
428 elif "MultipleChoice" in model_class:
429 code_sample = TF_MULTIPLE_CHOICE_SAMPLE if is_tf_class else PT_MULTIPLE_CHOICE_SAMPLE
430 elif "MaskedLM" in model_class:
431 code_sample = TF_MASKED_LM_SAMPLE if is_tf_class else PT_MASKED_LM_SAMPLE
432 elif "LMHead" in model_class:
433 code_sample = TF_CAUSAL_LM_SAMPLE if is_tf_class else PT_CAUSAL_LM_SAMPLE
434 elif "Model" in model_class:
435 code_sample = TF_BASE_MODEL_SAMPLE if is_tf_class else PT_BASE_MODEL_SAMPLE
436 else:
437 raise ValueError(f"Docstring can't be built for model {model_class}")
438
439 built_doc = code_sample.format(model_class=model_class, tokenizer_class=tokenizer_class, checkpoint=checkpoint)
440 fn.__doc__ = (fn.__doc__ or "") + "".join(docstr) + built_doc
441 return fn
442
443 return docstring_decorator
444
445
446def is_remote_url(url_or_filename):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected