Token Classification
Transformers
ONNX
Safetensors
English
Japanese
Chinese
bert
anime
filename-parsing
Eval Results (legacy)
Run this model with HF Jobs
Run ModerRAS/AniFileBERT on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/ModerRAS/AniFileBERT. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/ModerRAS/AniFileBERT on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use ModerRAS/AniFileBERT with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ModerRAS/AniFileBERT with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("token-classification", model="ModerRAS/AniFileBERT")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForTokenClassification tokenizer = AutoTokenizer.from_pretrained("ModerRAS/AniFileBERT") model = AutoModelForTokenClassification.from_pretrained("ModerRAS/AniFileBERT", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Add low-frequency DMHY audit gate
Browse filesFiles changed (2)
30 unmodified lines31323334353637383940414243444546474810 unmodified lines5960616263646566676830 unmodified lines --manifest-output reports\dmhy_weak.template_generated.top5000.rust.manifest.json```
Audit low-frequency recipe output from the repository root:
```powershellcargo run --release --manifest-path tools\rust_dmhy_template_apply\Cargo.toml -- ` --audit-low-frequency ` --input datasets\AnimeName\dmhy_list.jsonl ` --recipes reports\dmhy_template_recipes.full_top5000.seed.jsonl ` --audit-output reports\dmhy_low_frequency_audit.rust.jsonl ` --audit-max-count 50 ` --threads 24```
Optional controls:
```powershell10 unmodified linesrecord schema level: `filename`, `tokens`, `labels`, `template_id`, `template`,plus optional `source_filename`, `path_trimmed`, and`dropped_title_candidate_positions`.
For low-frequency templates (`count <= --audit-max-count`, default `50`), applyuses a conservative gate: records with `no_title`, `multiple_title_spans`,`path_retained`, or `hash_labeled` audit warnings are skipped from the trainingJSONL and left in the audit/review files. This keeps common templates stablewhile preventing rare ambiguous path/title cases from polluting the generateddataset.16 unmodified lines171819202122232424 unmodified lines4950515253545556575862 unmodified lines12112212312412512612743 unmodified lines17117217316717417517617716 unmodified lines19419519619719819920020132 unmodified lines23423523623723823924024124262 unmodified lines30530630730830931031131231313 unmodified lines327328329330331332333334335336337338339285 unmodified lines62562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978045 unmodified lines8268278288298308318328338348358368378388 unmodified lines847848849850851852853854855856857858859860861333 unmodified lines11951196119710101198119912001201120212031204120512061207120838 unmodified lines12471248124912501251125212531254125512 unmodified lines1268126912701271127212731274127512761277127874 unmodified lines13531354135511531356135713581359154 unmodified lines15141515151615171518151913141520152115221523171 unmodified lines169516961697169816991700170117021703170417051706170717081709171017111712171353 unmodified lines17671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179362 unmodified lines1856185718581619162016211622162318591860186118621863186418651866186718681869162616271628162916301631187018711872187318741875187618771878187918801881203 unmodified lines2085208620871841208820892090209120922093184420942095209620972098209921 unmodified lines21212122212321242125212621272128212921302131213287 unmodified lines2220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225119 unmodified lines227122722273227422752276227722782279228022812282228316 unmodified linesstruct Args { #[arg(long)] cluster: bool, #[arg(long)] audit_low_frequency: bool, #[arg(long, default_value = "datasets/AnimeName/dmhy_list.jsonl")] input: PathBuf, #[arg(long, default_value = "reports/dmhy_template_recipes.seed.jsonl")]24 unmodified lines recipes_output: PathBuf, #[arg(long, default_value = "reports/dmhy_template_review.rust.jsonl")] review_output: PathBuf, #[arg(long, default_value = "reports/dmhy_low_frequency_audit.rust.jsonl")] audit_output: PathBuf, #[arg(long, default_value_t = 50)] audit_max_count: u64, #[arg(long)] limit: Option<usize>, #[arg(long)]62 unmodified lines skipped_no_recipe: usize, skipped_sample_cap: usize, skipped_role_mismatch: usize, skipped_low_frequency_audit_warning: usize, written: usize,}
43 unmodified lines Lazy::new(|| Regex::new(r"^第[一二三四五六七八九十\d]+[季期部]$").unwrap());static SEASON_VALUE_RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?i)^S(\d{1,2})$").unwrap());static SPECIAL_RE: Lazy<Regex> = Lazy::new(|| { Regex::new(r"(?i)^(?:NCOP|NCED|OP|ED|PV|CM|SP|OVA|OAD|IV|Menu|Preview|Trailer|Teaser|Animatics?)(?:[\s_.-]?(?:\d{0,4}|Ep\d{1,4}|[A-Z]))?$").unwrap() Regex::new(r"(?i)^(?:NCOP|NCED|OP|ED|PV|CM|SP|OVA|OAD|IV|Menu|Intro|Preview|Trailer|Teaser|Animatics?)(?:[\s_.-]?(?:\d{0,4}|Ep\d{1,4}|[A-Z]))?$").unwrap()});static VOLUME_RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?i)^(?:Vol(?:ume)?\.?|Disc|CD|BD|DVD|D)\s*\d{1,3}$").unwrap());16 unmodified lines});static SEASON_WORD_NUMBER_RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?i)(?:season|saison)\s*0?(\d{1,2})").unwrap());static PLAIN_SEASON_SEGMENT_RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?i)^(?:season|saison)\s*0?\d{1,2}$|^s0?\d{1,2}$").unwrap());static S_NUMBER_SEGMENT_RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"(?i)(?:^|[^\p{L}\p{N}])s0?(\d{1,2})(?:$|[^\p{L}\p{N}])").unwrap());static SXE_SEASON_RE: Lazy<Regex> = Lazy::new(|| {32 unmodified lines if args.cluster { return run_cluster(&args); } if args.audit_low_frequency { return run_low_frequency_audit(&args); } if args.expand != "all" && args.expand != "sample" { bail!("--expand must be all or sample"); }62 unmodified lines "no_recipe" => stats.skipped_no_recipe += 1, "sample_cap" => stats.skipped_sample_cap += 1, "role_mismatch" => stats.skipped_role_mismatch += 1, "low_frequency_audit_warning" => { stats.skipped_low_frequency_audit_warning += 1 } _ => {} } }13 unmodified lines "selected_templates": recipes.len(), "confidence": args.confidence, "min_count": args.min_count, "low_frequency_audit_max_count": args.audit_max_count, "low_frequency_blocking_warnings": [ "hash_labeled", "multiple_title_spans", "no_title", "path_retained" ], "expand": args.expand, "sample_per_template": if args.expand == "sample" { Some(args.sample_per_template) } else { None }, "stats": stats,285 unmodified lines Ok(())}
fn run_low_frequency_audit(args: &Args) -> Result<()> { let recipes = load_recipes(args)?; let inputs = load_input(&args.input, args.limit)?; let low_template_total = recipes .values() .filter(|recipe| recipe.count.unwrap_or(0) <= args.audit_max_count) .count(); let mut seen_templates = HashSet::new(); let mut rows = Vec::new();
for original in inputs { if !args.keep_encoding_noise && (has_encoding_noise(&original) || has_non_anime_noise(&original) || has_abstract_path_noise(&original)) { continue; } let (training_filename, trimmed_parent) = training_filename_for(&original); let (key, _tokens, _classes, groups) = template_key_for_filename(&training_filename); let Some(recipe) = recipes.get(&key) else { continue; }; let count = recipe.count.unwrap_or(0); if count > args.audit_max_count || !seen_templates.insert(recipe.template_id.clone()) { continue; } if recipe.roles.len() != groups.len() { continue; } let Some(mut record) = dmhy_record(&training_filename, &recipe.template_id, &recipe.roles) else { continue; }; if trimmed_parent { record.source_filename = Some(original.clone()); record.path_trimmed = Some(true); } rows.push(json!({ "template_id": recipe.template_id, "count": count, "template": recipe.template, "filename": record.filename, "source_filename": record.source_filename, "path_trimmed": record.path_trimmed.unwrap_or(false), "spans": entity_spans(&record.tokens, &record.labels), "warnings": audit_warnings(&record), "tokens": record.tokens, "labels": record.labels, })); if seen_templates.len() >= low_template_total { break; } }
rows.sort_by(|a, b| { let count_a = a.get("count").and_then(Value::as_u64).unwrap_or(0); let count_b = b.get("count").and_then(Value::as_u64).unwrap_or(0); let id_a = a.get("template_id").and_then(Value::as_str).unwrap_or(""); let id_b = b.get("template_id").and_then(Value::as_str).unwrap_or(""); count_a.cmp(&count_b).then_with(|| id_a.cmp(id_b)) }); write_jsonl_values(&args.audit_output, &rows)?; let warning_counts = warning_counts(&rows); let manifest = json!({ "generated_at": Utc::now().to_rfc3339(), "input": args.input.to_string_lossy(), "recipes": args.recipes.to_string_lossy(), "audit_output": args.audit_output.to_string_lossy(), "audit_max_count": args.audit_max_count, "low_template_total": low_template_total, "audited_templates": rows.len(), "warning_counts": warning_counts, "implementation": "rust_dmhy_low_frequency_audit" }); println!("{}", serde_json::to_string_pretty(&manifest)?); Ok(())}
fn entity_spans(tokens: &[String], labels: &[String]) -> Vec<Value> { let mut spans = Vec::new(); let mut current_label: Option<String> = None; let mut current_text = String::new(); for (token, label) in tokens.iter().zip(labels.iter()) { let entity = label .strip_prefix("B-") .or_else(|| label.strip_prefix("I-")) .unwrap_or("O"); if current_label.as_deref() == Some(entity) { current_text.push_str(token); continue; } if let Some(label) = current_label.take() { if label != "O" { spans.push(json!({ "label": label, "text": current_text })); } } current_label = Some(entity.to_string()); current_text = token.clone(); } if let Some(label) = current_label { if label != "O" { spans.push(json!({ "label": label, "text": current_text })); } } spans}
fn audit_warnings(record: &Record) -> Vec<String> { let mut warnings = Vec::new(); let title_spans = entity_spans(&record.tokens, &record.labels) .into_iter() .filter(|span| span.get("label").and_then(Value::as_str) == Some("TITLE")) .count(); if title_spans == 0 { warnings.push("no_title".to_string()); } else if title_spans > 1 { warnings.push("multiple_title_spans".to_string()); } if !record.labels.iter().any(|label| label.ends_with("EPISODE")) { warnings.push("no_episode".to_string()); } if record.filename.contains('/') || record.filename.contains('\\') { warnings.push("path_retained".to_string()); } for (index, token) in record.tokens.iter().enumerate() { if HASH_RE.is_match(token) && record.labels.get(index).is_some_and(|label| label != "O") { warnings.push("hash_labeled".to_string()); break; } } warnings.sort(); warnings.dedup(); warnings}
fn warning_counts(rows: &[Value]) -> HashMap<String, usize> { let mut counts = HashMap::new(); for row in rows { if let Some(warnings) = row.get("warnings").and_then(Value::as_array) { for warning in warnings { if let Some(warning) = warning.as_str() { *counts.entry(warning.to_string()).or_default() += 1; } } } } counts}
fn process_filename( original: &str, args: &Args,45 unmodified lines } } }; if recipe.count.unwrap_or(0) <= args.audit_max_count && has_blocking_low_frequency_warning(&record) { return Processed::Skipped { reason: "low_frequency_audit_warning", trimmed_parent, }; } if trimmed_parent { record.source_filename = Some(original.to_string()); record.path_trimmed = Some(true);8 unmodified lines }}
fn has_blocking_low_frequency_warning(record: &Record) -> bool { audit_warnings(record).iter().any(|warning| { matches!( warning.as_str(), "hash_labeled" | "multiple_title_spans" | "no_title" | "path_retained" ) })}
fn tokenize(value: &str) -> Vec<String> { let mut output = Vec::new(); let mut index = 0;333 unmodified lines roles[*index] = "TITLE".to_string(); } } else if bracket_text.len() == 1 { roles[bracket_text[0]] = if text.is_empty() { "TITLE" } else { "GROUP" }.to_string(); roles[bracket_text[0]] = if text.is_empty() { "TITLE" } else if bracket_text[0] == *start { "GROUP" } else { "TITLE" } .to_string(); } for index in text { roles[index] = "TITLE".to_string();38 unmodified lines .collect(); if parts.len() >= 2 && filename_has_title(parts[parts.len() - 1]) { if parts.len() >= 3 && path_segment_has_season(parts[parts.len() - 2]) { if !path_segment_is_plain_season(parts[parts.len() - 2]) { return (parts[parts.len() - 1].to_string(), true); } let parent_seasons = path_segment_seasons(parts[parts.len() - 2]); let leaf_seasons = path_segment_seasons(parts[parts.len() - 1]); if parent_seasons12 unmodified lines }}
fn path_segment_is_plain_season(segment: &str) -> bool { let cleaned = strip_wrapper(segment).trim().to_string(); PLAIN_SEASON_SEGMENT_RE.is_match(&cleaned)}
fn path_segment_has_season(value: &str) -> bool { PATH_SEGMENT_SEASON_RE.is_match(value)}74 unmodified lines "SEASON" => Some("SEASON"), "SPECIAL" | "VOLUME" => Some("SPECIAL"), "RESOLUTION" => Some("RESOLUTION"), "SOURCE" | "HASH" => Some("SOURCE"), "SOURCE" => Some("SOURCE"), _ => None, }; entity.map_or_else(|| "O".to_string(), |entity| format!("B-{entity}"))154 unmodified lines if atom_class == "RESOLUTION" { return "B-RESOLUTION".to_string(); } if atom_class == "HASH" { return "O".to_string(); } if matches!(atom_class.as_str(), "MEDIA" | "LANG" | "HASH") { if matches!(atom_class.as_str(), "MEDIA" | "LANG") { return "B-SOURCE".to_string(); } if matches!(atom_class.as_str(), "SPECIAL" | "VOLUME") {171 unmodified lines "vol" | "volume" ) { let next_text_before_episode = (index + 1..roles.len()) .find(|&cursor| groups[cursor].class_name != "SEP") .is_some_and(|cursor| { groups[cursor].class_name == "TEXT" && roles[cursor + 1..] .iter() .any(|role| role.starts_with("EPISODE")) }); if next_text_before_episode { output[index - 2] = "TITLE".to_string(); output[index] = "TITLE".to_string(); continue; } output[index - 2] = "SPECIAL".to_string(); output[index] = "SPECIAL".to_string(); continue;53 unmodified lines output[index] = "SPECIAL".to_string(); continue; } if roles[index] == "TITLE" && matches!(text.as_str(), "第" | "話" | "话" | "回" | "集") { output[index] = "O".to_string(); continue; } if output[index] == "O" && groups[index].class_name == "TEXT" && roles[index + 1..].iter().any(|role| role.starts_with("EPISODE")) && text.chars().any(|ch| ch.is_alphabetic()) && !ep_markers.contains(&text.as_str()) { if let Some(last_title) = output[..index].iter().rposition(|role| role == "TITLE") { let episode_since_title = output[last_title + 1..index] .iter() .any(|role| role.starts_with("EPISODE")); if !episode_since_title { output[index] = "TITLE".to_string(); continue; } } } if roles[index] == "TITLE" && matches!(text.to_ascii_lowercase().as_str(), "season" | "saison") && index + 2 < roles.len()62 unmodified lines index += 1; continue; } if groups[index].class_name == "BRACKET_TEXT" { candidates.push((index, index + 1)); index += 1; continue; } let start = index; index += 1; loop { if index < roles.len() && roles[index] == "TITLE" && !(groups[index - 1].class_name == "BRACKET_TEXT" && groups[index].class_name == "BRACKET_TEXT") { index += 1; continue; } while index + 1 < roles.len() && roles[index] == "O" && groups[index].class_name == "SEP" && roles[index + 1] == "TITLE" { index += 2; if index + 1 < roles.len() && roles[index] == "O" && groups[index].class_name == "SEP" && roles[index + 1] == "TITLE" { index += 2; continue; } break; } candidates.push((start, index)); }203 unmodified lines
fn smooth_title_spans(tokens: &[String], labels: &[String]) -> Vec<String> { let joiners = [ " ", ".", "-", "_", "·", "・", "×", "/", "/", "'", "’", ":", ":", "!", "!", " ", ".", "-", "_", "·", "・", "×", "/", "/", "'", "’", ":", ":", "!", "!", "?", "?", ";", ";", ",", ",", "~", "~", "-", "(", ")", "(", ")", "[", "]", "【", "】", "「", "」", "「", "」", "☆", "@", ]; let title_terminal_punctuation = ["!", "!", "?", "?"]; let entity_joiners = [ " ", ".", "-", "_", "·", "・", "×", "/", "/", "'", "’", ":", ":", "!", "!", "&", "&", " ", ".", "-", "_", "·", "・", "×", "/", "/", "'", "’", ":", ":", "!", "!", "?", "?", ";", ";", ",", ",", "~", "~", "-", "(", ")", "(", ")", "[", "]", "【", "】", "「", "」", "「", "」", "☆", "@", "&", "&", ]; let mut output = labels.to_vec(); for (index, (token, label)) in tokens.iter().zip(labels.iter()).enumerate() {21 unmodified lines output[index] = left_label.clone(); } } if title_terminal_punctuation.contains(&token.as_str()) && index > 0 { let left_label = &output[index - 1]; if left_label == "B-TITLE" { output[index] = "B-TITLE".to_string(); } } } output}87 unmodified lines assert!(pso2.contains(&("Episode".to_string(), "B-TITLE".to_string()))); assert!(pso2.contains(&("Oracle".to_string(), "B-TITLE".to_string()))); assert!(pso2.contains(&("01".to_string(), "B-EPISODE".to_string()))); let aikatsu = labels_for("Aikatsu Friends! - S2E01 (BD 1920x1080 x264 FLAC)"); assert!(aikatsu.contains(&("!".to_string(), "B-TITLE".to_string()))); let intro = labels_for("[VCB-Studio] LoveLive! µ's Live Collection [01][intro][1080p]"); assert!(intro.contains(&("intro".to_string(), "B-SPECIAL".to_string()))); let hash = labels_for("[Group][Title][01][1080p][00270AC8]"); assert!(hash.contains(&("00270AC8".to_string(), "O".to_string()))); let yamato = labels_for("[1995.01] YAMATO2520 Vol.1 明日への希望-0001"); assert!(yamato.contains(&("YAMATO2520".to_string(), "B-TITLE".to_string()))); assert!(yamato.contains(&("明日への希望".to_string(), "B-TITLE".to_string()))); let ubw = labels_for("Fate/stay night [Unlimited Blade Works] #00 「プロローグ」"); assert!(ubw.contains(&("Unlimited".to_string(), "B-TITLE".to_string()))); assert!(!ubw.contains(&("Unlimited".to_string(), "B-GROUP".to_string()))); let alias_title = labels_for("[Koten_Gars] Tegami Bachi; Letter Bee - 01 [1080p]"); assert!(alias_title.contains(&(";".to_string(), "B-TITLE".to_string()))); let comma_title = labels_for("[Studio GreenTea] Kamiina Botan, Yoeru Sugata wa Yuri no Hana [01]"); assert!(comma_title.contains(&(",".to_string(), "B-TITLE".to_string()))); let happy_lesson = labels_for("【DVD】 HAPPY☆LESSON THE TV 第01話"); assert!(happy_lesson.contains(&("☆".to_string(), "B-TITLE".to_string()))); let idolmaster = labels_for("[CASO&SumiSora][THE_IDOLM@STER_CINDERELLA_GIRLS][07.5_SP]"); assert!(idolmaster.contains(&("@".to_string(), "B-TITLE".to_string()))); let soul_taker = labels_for("[AI-Raws] THE SOUL TAKER~魂狩~ #01 (HEVC 1312x720)"); assert!(soul_taker.contains(&("~".to_string(), "B-TITLE".to_string()))); let mayoi = labels_for("[Snow-Raws] 迷家[マヨイガ] 第01話"); assert!(mayoi.contains(&("迷家".to_string(), "B-TITLE".to_string()))); assert!(mayoi.contains(&("マヨイガ".to_string(), "B-TITLE".to_string())));
let conan_time = labels_for("【蓝色狂想】名侦探柯南TV版第036集-周一晚上7点半杀人事件"); assert!(conan_time.contains(&("036".to_string(), "B-EPISODE".to_string())));19 unmodified lines trimmed, "Season 4/E07 - The New Woody Woodpecker Show (Season 1-4) (1999-2002) WEB-DL 720p" ); let pokemon = "Pokémon Season 2 - Orange League [Ep. 83-118]/Pokemon - 084 - OL002 - A Scare in the Air [DVD][PM-Dragon-x264-AC3][00270AC8]"; let (trimmed_pokemon, pokemon_was_trimmed) = training_filename_for(pokemon); assert!(pokemon_was_trimmed); assert_eq!( trimmed_pokemon, "Pokemon - 084 - OL002 - A Scare in the Air [DVD][PM-Dragon-x264-AC3][00270AC8]" ); let woody = labels_for(&trimmed); assert!(woody.contains(&("4".to_string(), "B-SEASON".to_string()))); assert!(woody.contains(&("E".to_string(), "O".to_string())));tools/rust_dmhy_template_apply/README.md+19
tools/rust_dmhy_template_apply/src/main.rs+308-17