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

Function clean_model_doc_toc

src/transformers/utils/check_doc_toc.py:44–77  ·  view source on GitHub ↗

Cleans a section of the table of content of the model documentation (one specific modality) by removing duplicates and sorting models alphabetically. Args: model_doc (`List[dict]`): The list of dictionaries extracted from the `_toctree.yml` file for this specific mo

(model_doc: List[dict])

Source from the content-addressed store, hash-verified

42
43
44def clean_model_doc_toc(model_doc: List[dict]) -> List[dict]:
45 """
46 Cleans a section of the table of content of the model documentation (one specific modality) by removing duplicates
47 and sorting models alphabetically.
48
49 Args:
50 model_doc (`List[dict]`):
51 The list of dictionaries extracted from the `_toctree.yml` file for this specific modality.
52
53 Returns:
54 `List[dict]`: List of dictionaries like the input, but cleaned up and sorted.
55 """
56 counts = defaultdict(int)
57 for doc in model_doc:
58 counts[doc["local"]] += 1
59 duplicates = [key for key, value in counts.items() if value > 1]
60
61 new_doc = []
62 for duplicate_key in duplicates:
63 titles = list({doc["title"] for doc in model_doc if doc["local"] == duplicate_key})
64 if len(titles) > 1:
65 raise ValueError(
66 f"{duplicate_key} is present several times in the documentation table of content at "
67 "`docs/source/en/_toctree.yml` with different *Title* values. Choose one of those and remove the "
68 "others."
69 )
70 # Only add this once
71 new_doc.append({"local": duplicate_key, "title": titles[0]})
72
73 # Add none duplicate-keys
74 new_doc.extend([doc for doc in model_doc if counts[doc["local"]] == 1])
75
76 # Sort
77 return sorted(new_doc, key=lambda s: s["title"].lower())
78
79
80def check_model_doc(overwrite: bool = False):

Callers 1

check_model_docFunction · 0.85

Calls 1

itemsMethod · 0.45

Tested by

no test coverage detected