MCPcopy Create free account
hub / github.com/ModalityDance/Omni-R1 / find_labels

Function find_labels

src/transformers/src/transformers/utils/generic.py:565–584  ·  view source on GitHub ↗

Find the labels used by a given model. Args: model_class (`type`): The class of the model.

(model_class)

Source from the content-addressed store, hash-verified

563
564
565def find_labels(model_class):
566 """
567 Find the labels used by a given model.
568
569 Args:
570 model_class (`type`): The class of the model.
571 """
572 model_name = model_class.__name__
573 framework = infer_framework(model_class)
574 if framework == "tf":
575 signature = inspect.signature(model_class.call) # TensorFlow models
576 elif framework == "pt":
577 signature = inspect.signature(model_class.forward) # PyTorch models
578 else:
579 signature = inspect.signature(model_class.__call__) # Flax models
580
581 if "QuestionAnswering" in model_name:
582 return [p for p in signature.parameters if "label" in p or p in ("start_positions", "end_positions")]
583 else:
584 return [p for p in signature.parameters if "label" in p]
585
586
587def flatten_dict(d: MutableMapping, parent_key: str = "", delimiter: str = "."):

Callers 7

test_find_labels_ptMethod · 0.90
test_find_labels_tfMethod · 0.90
test_find_labels_flaxMethod · 0.90
prepare_tf_datasetMethod · 0.85
train_stepMethod · 0.85
test_stepMethod · 0.85
__init__Method · 0.85

Calls 1

infer_frameworkFunction · 0.85

Tested by 4

test_find_labels_ptMethod · 0.72
test_find_labels_tfMethod · 0.72
test_find_labels_flaxMethod · 0.72
test_stepMethod · 0.68