Hugging Face ML インターン入門:最初の ML エージェントの構築
KDnuggets は、Hugging Face の ML インターンプログラムを通じて、初心者向けに機械学習エージェントの構築手順を解説している。
キーポイント
インターンシッププログラムの紹介
Hugging Face が提供する ML インターンシッププログラムへの参加方法と、その教育カリキュラムの内容について言及されている。
ML エージェント構築の基礎知識
機械学習エージェントとは何かという概念説明から始め、基本的な構成要素や動作原理を解説している。
実践的な構築ステップ
具体的なコード例やツールを使用して、初めてのエージェントをゼロから作成する手順が段階的に示されている。
重要な引用
Getting Started with Hugging Face ML Intern: Your First ML Agent
影響分析・編集コメントを表示
影響分析
この記事は、機械学習分野への参入障壁を下げる教育コンテンツとして機能し、特に初学者がエージェント技術を実践する際の道標となる。Hugging Face のエコシステムを活用した学習アプローチの普及を促す効果がある。
編集コメント
教育リソースとしての質が高く、実務未経験者や学生にとって具体的な学習ロードマップを提供する有益な記事です。
image**
論文を読んだという段階から、ハブ上にトレーニング済みのチェックポイントがある状態に至るまでのギャップが、週末丸ごと食いつぶしてしまうような、よくある状況に陥ったことはありませんか?ML Intern は、このギャップを縮小しようとする Hugging Face**の試みです。これは Hugging Face が提供するオープンソースのコマンドラインインターフェース (CLI) エージェントであり、自然な英語で機械学習タスクを記述することを可能にします。
手作業で全てを組み立てる代わりに、モデルのファインチューニングや研究論文の探索、トレーニング実行の開始などを指示するだけで済みます。これは通常、ジュニアの機械学習エンジニアが行うような業務、つまりドキュメントの読解、GitHub での検索、スクリプトの作成、ジョブの実行、結果の確認、そして反復処理を担います。
このエージェントは Hugging Face のスタックをエンドツーエンドで構築されています。ハブ上の論文や arXiv を検索したり、データセットと連携したり、HF Jobs を使用してグラフィックスプロセッシングユニット (GPU) によるトレーニングジョブを開始したり、Trackio で実験をログ記録したりできます。また、完了した際にはトレーニング済みのモデルをハブへ公開することも可能です。内部では smolagents フレームワークを使用しており、API クレジットを消費したくない場合は Hugging Face Inference Providers を経由するか、ローカルエンドポイントを通じてモデル呼び出しをルーティングします。
これは単なる「コードのための ChatGPT」というよりは、実際にシェルアクセス権限と Hugging Face アカウントを持つ研究インターンのようなものです。リポジトリは huggingface/ml-intern です。これを実験に利用したり、自分のニーズに合わせて適応させたり、さらには継続的インテグレーション(CI)ワークフローの一部として組み込んだりすることも可能です。
# ML Intern が役立つ理由の理解
**
実際の機械学習研究は直線的ではありません。何かを読み、引用を追跡し、ほぼ条件に合うデータセットを見つけ、データローダーを二度書き直し、トレーニングを行い、評価が間違っていたことに気づいて修正し、再度トレーニングを行います。ML Intern は、こうした反復的な作業の多くを自動化するように設計されており、設定コードを繰り返し記述する代わりに、研究上の意思決定に集中できるようにします。
従来のチャットボットとは異なり、一つの回答を生成してそこで終わることはありません。むしろ、反復的なワークフローに従います。

ML Intern のワークフローループ
Hugging Face は、小規模な Qwen モデル上でわずか 10 時間以内に、科学推論のためのベンチマークである GPQA で、エージェントの性能が約 10% から約 32% に向上したという結果を発表しました。この特定のベンチマークにあなたが関心があるかどうかは別として、これは一度スクリプトを書いて終わるおもちゃではないことをよく示しています。これは継続して動作するように作られています。
これでプロジェクトが存在する理由を理解するのに十分な背景知識が得られました。次は実際に使用するときですが、その前に必要なセットアップが整っているか確認してください。
# 前提条件の確認
Hugging Face のアカウント、Python、uv、そしていくつかのトークンが必要です。
トークン
なぜ必要なのか?
推奨される権限
HF_TOKEN
Hugging Face Hub、推論プロバイダー、GPU サンドボックス、トレーニングジョブへのアクセス。
書き込み(推奨)または、探索のみでアップロードしない場合は読み取り
GITHUB_TOKEN
エージェントが参照実装を探す際に、公開 GitHub リポジトリを検索する。
公開リポジトリに対する読み取り専用アクセスを持つ細粒度トークン
HF_TOKEN をスキップすると、完全にローカルモデルを実行していない限り、CLI は初回起動時にトークンの入力を求めます。どちらのトークンを作成するか不明な場合は、Hugging Face アクセストークンおよびGitHub 個人用アクセストークンの公式ガイドを確認してください。
ML Intern のインストール
以下のコマンドをコピーして実行してください。
git clone git@github.com:huggingface/ml-intern.git
cd ml-intern
uv sync
uv tool install -e .
これで完了すれば、ml-intern はどのディレクトリからでも使用可能になります。簡単な動作確認として:
ml-intern --help
以下の内容を .env ファイルに追加するか、シェルで同等の変数をエクスポートしてください。
HF_TOKEN=hf_your_token_here
GITHUB_TOKEN=ghp_your_token_here
インタラクティブモードとヘッドレスモードの比較
最初のランを実行する前に、エージェントがサポートする 2 つのモードを理解しておくと役立ちます。
// インタラクティブモードの使用
以下のコマンドを実行して機械学習エージェントを起動してください。
ml-intern
これによりチャットセッションが開かれます。やりたいことを説明すると、エージェントは手順を計画し、危険な操作の前には承認を求めながら、作業中は随時状況を報告してくれます。会話中にモデルを切り替えることも可能で、そのコマンドは以下の通りです。
/model
初心者におすすめのプロンプト例は以下の通りです。
- "Hub 上で小さな分類用データセットを見つけ、datasets ライブラリを使って読み込む方法を教えてください。"
- "この論文の要約を記述し、使用されているデータセットの一覧を示してください:[arXiv リンク]。"
- "Qwen2.5-0.5B のための最小限の低ランク適応 (LoRA) 微調整スクリプトを、小さな公開データセット上で作成してください。まだトレーニングを開始せず、スクリプトのみを書いてください。"
// ヘッドレスモードの使用
ml-intern "fine-tune llama on my dataset"
このモードでは単一のプロンプトを使用し、アクションの承認は自動で行われます。エージェントは完了するか、反復回数の上限に達するまで実行されます。これは夜間の実験用に GitHub Action に組み込む際に使用するモードです。
慣れてきたら、以下のフラグが役立ちます。
ml-intern --max-iterations 100 "your prompt" # バジェットを制限する
ml-intern --no-stream "your prompt" # CI ログ用のクリーンな出力
ml-intern --sandbox-tools "test this in a GPU sandbox"
ml-intern --model moonshotai/Kimi-K2.7-Code:novita "your prompt"
まだ始めたばかりの場合は、まずインタラクティブモードを試してください。慣れてきたら、自動化のためにヘッドレスモードに切り替えてください。
# 最初のランニングを開始する
両方のモードで同じプロンプトを使用することで、その違いを確認できます。まずはトレーニングを伴わない小規模なタスクから始めましょう。目標は単に Hugging Face Hub からデータセットを見つけ、ローダースクリプトを作成することです。
プロンプト:
Hub 上の rotten_tomatoes データセットを探し、datasets ライブラリを使用してそれをロードし、最初の例を出力する短い Python スクリプトを作成してください。ファイル名は load_dataset.py に保存してください。トレーニングは実行しないでください。
開始前に .env ファイルに HF_TOKEN と GITHUB_TOKEN の両方が含まれていることを確認してください。
// インタラクティブモードでの実行
チャットセッションを開き、プロンプトを入力してその動作を確認し、必要に応じて追跡質問を行います。
次のコマンドを実行します:
ml-intern
その後、> prompt: のプロンプトで以下を入力してください:
Hub 上の rotten_tomatoes データセットを探し、datasets ライブラリを使用してそれをロードし、最初の例を出力する短い Python スクリプトを作成してください。ファイル名は /tmp/load_dataset_interactive.py に保存してください。トレーニングは実行しないでください。
出力:
エージェントランタイムを初期化中...
ユーザー:kanwal8008
モデル:zai-org/GLM-5.2:novita
ツールランタイム:ローカルファイルシステム
読み込まれたツール:25 個
/help でコマンド一覧 · /model でモデル切り替え · /quit で終了
準備完了。素晴らしいものを作りましょう。
Hub から rotten_tomatoes データセットを検索し、datasets ライブラリを使用してロードする短い Python スクリプトを作成して、最初の例を出力してください。スクリプトは /tmp/load_dataset_interactive.py に保存してください。トレーニングは実行しないでください。
データセットは cornell-movie-review-data/rotten_tomatoes です。デフォルトの構成が 1 つあり、トレーニング・検証・テストのスプリットが含まれています。カラムは text と label です。スクリプトを作成中です。
▸ write {"content": "\"\"\"HF Hub から rotten_tomatoes データセットをロードして最初の例を出力する...\"\"\""}
完了。スクリプトは /tmp/load_dataset_interactive.py に保存されました。
このスクリプトの動作:
- datasets.load_dataset を使用して cornell-movie-review-data/rotten_tomatoes をロード
- スプリット一覧(train, validation, test)を出力
- トレーニングデータの最初の例({"text": ..., "label": ...} の辞書形式)を出力
データセットの詳細:
- カラム:text(映画レビュー文)、label(0 = ネガティブ、1 = ポジティブ)
- 総数約 1.06 万件(ポジティブ 5,331 / ネガティブ 5,331)
ローカルで実行するには以下を実行してください:
python /tmp/load_dataset_interactive.py
/quit
さようなら。
作成されたファイル (/tmp/load_dataset_interactive.py):
"""HF Hub から rotten_tomatoes データセットをロードして最初の例を出力する。"""
from datasets import load_dataset
Hub から完全なデータセット(すべてのスプリット)をロード
ds = load_dataset("cornell-movie-review-data/rotten_tomatoes")
print("Dataset splits:", list(ds.keys()))
first_train = ds["train"][0]
print("First training example:")
print(first_train)
print("\nLabel meaning: 0 = negative, 1 = positive")
インタラクティブモードでは、スクリプトが実行する内容やデータセットの詳細、実行方法など、より多くのコンテキストを提供します。また、/quit を入力する前に追加の質問をすることも可能です。
// ヘッドレスモードでの実行
このコマンドを実行すると、エージェントは開始から終了まで一連の処理を行い、その後終了します。
以下のコマンドを実行してください:
ml-intern --max-iterations 15 --no-stream \
"Find the rotten_tomatoes dataset on the Hub and write a short Python script that loads it with datasets and prints the first example. Save it to /tmp/load_dataset.py. Do not run training."
出力:
HF トークンの読み込み完了
モデル:zai-org/GLM-5.2:novita
ツールランタイム:ローカルファイルシステム
最大反復回数:15
プロンプト:Hugging Face Hub 上で rotten_tomatoes データセットを検索し、datasets ライブラリを使用してそれを読み込む短い Python スクリプトを作成して、最初の例を出力してください。これを /tmp/load_dataset.py に保存してください。トレーニングは実行しないでください。
▸ hf_inspect_dataset {"dataset": "cornell-movie-review-data/rotten_tomatoes", "sample_rows": 1}
▸ write {"content": "from datasets import load_dataset\n\ndataset = load_dataset(\"rotte..."}
▸ bash {"command": "cd /tmp && python load_dataset.py", "description": "Run the dataset..."}
完了。スクリプトは /tmp/load_dataset.py に保存され、動作確認済みです。これは datasets.load_dataset を介して rotten_tomatoes データセット(データセット ID: cornell-movie-review-data/rotten_tomatoes)を読み込み、最初のトレーニング例を出力します:
{'text': 'the rock is destined to be the 21st century\'s new " conan " ...',
'label': 1}
このデータセットには 2 つの列があります。テキスト(レビュー内容)とラベル(0 = ネガティブ、1 = ポジティブ)です。これはトレーニング用(8,530 行)、検証用(1,066 行)、テスト用(1,066 行)に分割されています。
--- エージェントターン完了 (履歴サイズ=9) ---
作成されたファイル (/tmp/load_dataset.py):
from datasets import load_dataset
dataset = load_dataset("rotten_tomatoes", split="train")
print(dataset[0])
ヘッドレスモードでは、すべての操作が自動的に承認されます。これは、何をすべきかを知っており、実行の途中で制御する必要がない場合に便利です。
ローカルモデルを使用した ML Intern の実行
もし Hugging Face の推論プロバイダーを使用したり、API 利用料を支払ったりしたくない場合は、ML Intern はローカルでホストされたモデルとも連携できます。ML Intern は自らモデルの重みをダウンロードして読み込むのではなく、すでにあなたのマシン上で稼働している OpenAI 互換サーバーに接続します。
つまり、以下のような人気のあるローカル推論フレームワークを利用可能です:
- Ollama
- vLLM
- LM Studio
- llama.cpp
例えば、Ollama を使用している場合は、以下を実行できます:
ml-intern --model ollama/llama3.1:8b "このリポジトリの README を要約してください。"
あるいは、vLLM でモデルを実行している場合は以下のようになります:
ml-intern --model vllm/meta-llama/Llama-3.1-8B-Instruct "プロンプトを入力"
ローカルモデルサーバーがカスタムエンドポイントで稼働している場合、環境変数を使用して設定できます:
LOCAL_LLM_BASE_URL=http://localhost:8000
LOCAL_LLM_API_KEY=optional-if-your-server-requires-it
一部のプロバイダーは独自の設定用環境変数をサポートしています。例えば、Ollama を使用している場合は OLLAMA_BASE_URL を設定でき、これは汎用的な LOCAL_LLM_BASE_URL よりも優先されます。重要な注意点として、非常に小さなローカルモデルでは多段階のトレーニングパイプラインを処理するのは困難です。探索やスクリプト作成には問題ありませんが、本格的なエージェントループには、より推論能力に余裕のあるモデルが必要です。
# ML Intern の仕組みを理解する
アーキテクチャを丸暗記する必要はありませんが、なぜエージェントが時々停止して承認を求めるのかを理解しておくと役立ちます。デフォルトでは、エージェントは最大 300 ターンにわたる反復ループを実行します。以下のフローチャートは、各呼び出しで何が起こっているかのおおよそのイメージを示しています。

ML Intern が各呼び出しを処理する方法
ML Intern の最大の強みの一つは、標準状態で使用可能なツールの数です。組み込みツールには HF エコシステム(ドキュメント、データセット、リポジトリ、論文、ジョブ)に加え、GitHub 検索、ローカルファイル操作、プランニング支援機能が含まれており、さらに Model Context Protocol (MCP) を通じてユーザーが追加したツールも利用可能です。また、同じ引数で繰り返されるツール呼び出しを検出する「ドゥームループ検知機能」も備えており、過去にコーディングエージェントを使用したことがある方にとっては馴染み深い問題への対策です。
すべてのセッションは、Hub アカウント上のプライベートデータセット({username}/ml-intern-sessions)へ自動アップロードされ、Agent Trace Viewer が認識できる形式で保存されます。これらのトレースはデバッグに特に有用です。なぜなら、エージェントがどの推論ステップを踏んだかを一つずつ確認できるからです。何か問題が発生した場合、セッションを Agent Trace Viewer で開くことで、エージェントがどこで誤った判断を下したのかを正確に把握できます。
また、セッション中のトレースの共有方法を以下のように制御することも可能です:
/share-traces private
/share-traces public
セッション履歴を保存したくない場合は、設定ファイルを通じてトレースのアップロード自体を無効にすることもできます。
一般的なミスを避ける
- プロンプトは具体的に記述してください。「llama のファインチューニング」は曖昧です。「imdb データセット上で meta-llama/Llama-3.2-1B を LoRA でファインチューニングし、最大 1 エポックとし、Hub へのプッシュを行わない」という方がはるかに優れています。
- 承認プロセスに注意してください。トレーニングジョブやサンドボックスにはコストがかかります。エージェントが確認を求めてくるため、最初の実行ではすべての要求に盲目的に承認しないでください。
- 実験中の場合は --max-iterations パラメータを設定してください。デフォルトの 300 イテレーションという制限は複雑なタスクには最適ですが、テスト中には計算リソースを無駄にする可能性があります。
- トレースを確認してください。何か奇妙なことが起きた場合、Hub 上のプライベートセッションデータセットがブラックボックスレコーダーとして機能します。
次のステップへ進む
**
ML Intern はあなたの判断力を代替するものではありません。トレーニングログを読み込み、評価の妥当性を確認し、GPQA で 32% という結果が本当に望んでいたものかどうかを決定するのは依然としてあなた自身です。しかし、どこから手をつけていいか分からない空白の train.py を見つめ続けていた経験があるなら、Hub の使い方を既に知っているインターンがいることは強力な第一歩となります。
ml-intern を実行し、小さなタスクを与えてその挙動を確認してください。これが初期段階でのゲームです。いくつかの実践的な次のステップを挙げます:
- GitHub リポジトリを探訪する。ソースコードを閲覧し、例を確認し、新機能や改善点について最新情報をキャッチアップしましょう。
- 独自のカスタムツールを作成する。ML Intern は拡張可能に設計されています。agent/core/tools.py ファイルを修正して独自のツールを追加し、パッケージを再インストールすることで実現できます:
uv tool install -e . --force
- MCP サーバーに接続します。MCP を使用している場合、configs/cli_agent_config.json ファイルを更新することで、外部ツールやサービスをアタッチできます。${YOUR_TOKEN} などの環境変数は、自動的に.env ファイルから読み込まれます。
- Slack の通知を有効化します。完了時にアラートを受け取りたい場合は、SLACK_BOT_TOKEN と SLACK_CHANNEL_ID を設定してください。
Kanwal Mehreen は、機械学習エンジニアであり技術ライターです。データサイエンスと AI と医療の交差点に対する深い情熱を持っています。彼女は電子書籍「ChatGPT で生産性を最大化する」の共著者でもあります。APAC 地域の Google Generation Scholar 2022 に選出され、多様性と学術的卓越性を提唱しています。また、Teradata Diversity in Tech Scholar、Mitacs Globalink Research Scholar、Harvard WeCode Scholar としても認定されています。Kanwal は変革の熱心な支持者であり、STEM 分野における女性のエンパワーメントを目的とした FEMCodes を設立しました。
原文を表示

**
Have you ever gotten stuck in that familiar situation where you have a model idea, but the gap between “I read the paper” and “I have a trained checkpoint on the Hub” still eats up an entire weekend? ML Intern is Hugging Face**'s attempt to shrink that gap. It is an open-source command-line interface (CLI) agent from Hugging Face that lets you describe machine learning tasks in plain English.
Instead of manually piecing everything together, you can ask it to fine-tune a model, explore a research paper, or start a training run. It handles the kind of work a junior machine learning engineer would usually do: reading docs, searching GitHub, writing scripts, kicking off jobs, checking results, and iterating.
It is built on the Hugging Face stack end to end. It can search papers on the Hub and arXiv, work with datasets, launch graphics processing unit (GPU) training jobs using HF Jobs, log experiments with Trackio, and publish trained models back to the Hub when everything is done. Under the hood, it uses the smolagents framework and routes model calls through Hugging Face Inference Providers or local endpoints if you would rather not burn API credits.
It is less like “ChatGPT for code” and more like a research intern who actually has shell access and a Hugging Face account. The repository is huggingface/ml-intern. You can experiment with it, adapt it to your needs, or even make it part of your continuous integration (CI) workflow.
# Understanding Why ML Intern Helps
**
Real machine learning research is not linear. You read something, chase a citation, find a dataset that almost fits, rewrite the data loader twice, train, realize your evaluation was wrong, fix it, and train again. ML Intern is designed to automate much of this repetitive work so you can focus on research decisions instead of repeatedly writing setup code.
Unlike traditional chatbots, it does not stop after generating one answer. Instead, it follows an iterative workflow.

The ML Intern workflow loop
Hugging Face published results showing the agent improving from about 10% to about 32% on GPQA, a benchmark for scientific reasoning, in under 10 hours on a small Qwen model. Whether or not you care about that specific benchmark, it still gives you a good sense that this is not a toy that writes one script and stops. It is built to keep going.
That is enough background to understand why the project exists. Now it is time to use it, but first, make sure you have the required setup in place.
# Checking the Prerequisites
You will need a Hugging Face account, Python, uv**, and a few tokens.
Token
Why Is It Needed?
Recommended Permission
HF_TOKEN
Access the Hugging Face Hub, Inference Providers, GPU sandboxes, and training jobs.
Write (recommended) or Read if you only plan to explore and will not upload anything
GITHUB_TOKEN
Search public GitHub repositories when the agent looks for reference implementations.
Fine-grained token with read-only access to public repositories
If you skip HF_TOKEN, the CLI will ask for one on first launch unless you are running a fully local model. If you are unsure how to create either token, check the official guides for Hugging Face Access Tokens and GitHub Personal Access Tokens.
# Installing ML Intern
**
Copy and run the following commands.
git clone git@github.com:huggingface/ml-intern.git
cd ml-intern
uv sync
uv tool install -e .Once that is done, ml-intern works from any directory. A quick sanity check:
ml-intern --helpAdd the following to your .env file, or export equivalent variables in your shell.
HF_TOKEN=hf_your_token_here
GITHUB_TOKEN=ghp_your_token_here# Comparing Interactive and Headless Modes
Before starting your first run, it helps to understand the two modes the agent supports.
// Using Interactive Mode
Run the following command to launch your machine learning agent.
ml-internThis opens a chat session. You can describe what you want, the agent plans the steps, asks for approval before risky operations, and keeps you updated as it works. You can even swap models mid-conversation with:
/modelSome good prompts for a beginner are:
- "Find a small classification dataset on the Hub and show me how to load it with the datasets library."
- "Summarize this paper and list what datasets it uses: [arXiv link]."
- "Write a minimal low-rank adaptation (LoRA) fine-tuning script for Qwen2.5-0.5B on a tiny public dataset. Do not launch training yet, just write the script."
// Using Headless Mode
ml-intern "fine-tune llama on my dataset"This mode uses a single prompt and auto-approves actions. The agent runs until it finishes or hits the iteration limit. This is the mode you would drop into a GitHub Action for nightly experiments.
Some useful flags once you are comfortable:
ml-intern --max-iterations 100 "your prompt" # cap the budget
ml-intern --no-stream "your prompt" # cleaner output for CI logs
ml-intern --sandbox-tools "test this in a GPU sandbox"
ml-intern --model moonshotai/Kimi-K2.7-Code:novita "your prompt"If you are just getting started, try interactive mode first. Once you are comfortable, switch to headless mode for automation.
# Starting Your First Run
Use the same prompt in both modes so you can see how they differ. We will start with a small task that does not involve training. The goal is simply to find a dataset on the Hugging Face Hub and write a loader script.
The prompt:
Find the rotten_tomatoes dataset on the Hub and write a short Python script that loads it with datasets and prints the first example. Save it to load_dataset.py. Do not run training.Make sure your .env file includes both HF_TOKEN and GITHUB_TOKEN before you begin.
// Running in Interactive Mode
You open a chat session, type the prompt, watch it work, and follow up if needed.
Run this command:
ml-internThen type your prompt at the > prompt:
Find the rotten_tomatoes dataset on the Hub and write a short Python script that loads it with datasets and prints the first example. Save it to /tmp/load_dataset_interactive.py. Do not run training.Output:
Initializing agent runtime...
User: kanwal8008
Model: zai-org/GLM-5.2:novita
Tool runtime: local filesystem
Tools: 25 loaded
/help for commands · /model to switch · /quit to exit
Ready. Let's build something impressive.
> Find the rotten_tomatoes dataset on the Hub and write a short Python script that loads it with datasets and prints the first example. Save it to /tmp/load_dataset_interactive.py. Do not run training.
The dataset is cornell-movie-review-data/rotten_tomatoes. It has a single default config with train/validation/test splits, columns are text and label. Writing the script now.
▸ write {"content": "\"\"\"Load the rotten_tomatoes dataset from the HF Hub and print th..."}
Done. The script is saved to /tmp/load_dataset_interactive.py.
What it does:
- Loads cornell-movie-review-data/rotten_tomatoes via datasets.load_dataset
- Prints the list of splits (train, validation, test)
- Prints the first training example (a {"text": ..., "label": ...} dict)
Dataset details:
- Columns: text (movie review sentence), label (0 = negative, 1 = positive)
- ~10.6k examples total (5,331 positive / 5,331 negative)
You can run it locally with:
python /tmp/load_dataset_interactive.py
> /quit
Bye.File it created (/tmp/load_dataset_interactive.py):
"""Load the rotten_tomatoes dataset from the HF Hub and print the first example."""
from datasets import load_dataset
# Load the full dataset (all splits) from the Hub
ds = load_dataset("cornell-movie-review-data/rotten_tomatoes")
print("Dataset splits:", list(ds.keys()))
first_train = ds["train"][0]
print("First training example:")
print(first_train)
print("\nLabel meaning: 0 = negative, 1 = positive")Interactive mode gives you more context as it works, including dataset details, what the script does, and how to run it. You can also ask follow-up questions before typing /quit.
// Running in Headless Mode
One command, the agent runs from start to finish, then exits.
Run this command:
ml-intern --max-iterations 15 --no-stream \
"Find the rotten_tomatoes dataset on the Hub and write a short Python script that loads it with datasets and prints the first example. Save it to /tmp/load_dataset.py. Do not run training."Output:
HF token loaded
Model: zai-org/GLM-5.2:novita
Tool runtime: local filesystem
Max iterations: 15
Prompt: Find the rotten_tomatoes dataset on the Hub and write a short Python script that loads it with datasets and prints the first example. Save it to /tmp/load_dataset.py. Do not run training.
---
▸ hf_inspect_dataset {"dataset": "cornell-movie-review-data/rotten_tomatoes", "sample_rows": 1}
▸ write {"content": "from datasets import load_dataset\n\ndataset = load_dataset(\"rotte..."}
▸ bash {"command": "cd /tmp && python load_dataset.py", "description": "Run the dataset..."}
Done. The script is saved at /tmp/load_dataset.py and verified working. It loads the rotten_tomatoes dataset (dataset ID: cornell-movie-review-data/rotten_tomatoes) via datasets.load_dataset and prints the first training example:
{'text': 'the rock is destined to be the 21st century\'s new " conan " ...',
'label': 1}
The dataset has two columns -- text (the review) and label (0 = negative, 1 = positive) -- across train (8,530 rows), validation (1,066), and test (1,066) splits.
--- Agent turn_complete (history_size=9) ---File it created (/tmp/load_dataset.py):
from datasets import load_dataset
dataset = load_dataset("rotten_tomatoes", split="train")
print(dataset[0])Headless mode auto-approves everything. This is useful when you know what you want and do not need to steer the run in the middle.
# Running ML Intern With Local Models
If you would rather not use Hugging Face Inference Providers or pay for API usage, ML Intern can also work with locally hosted models. Instead of downloading and loading model weights itself, ML Intern connects to an OpenAI-compatible server that is already running on your machine.
That means you can use popular local inference frameworks such as:
- Ollama
- vLLM
- LM Studio
- llama.cpp
For example, if you are using Ollama, you can run:
ml-intern --model ollama/llama3.1:8b "Summarize the README in this repository."Or, if you are running a model with vLLM:
ml-intern --model vllm/meta-llama/Llama-3.1-8B-Instruct "Your prompt"If your local model server is running on a custom endpoint, you can configure it with environment variables:
LOCAL_LLM_BASE_URL=http://localhost:8000
LOCAL_LLM_API_KEY=optional-if-your-server-requires-itSome providers also support their own environment variables. For example, if you are using Ollama, you can set OLLAMA_BASE_URL, which takes precedence over the generic LOCAL_LLM_BASE_URL. One important thing to keep in mind is that a tiny local model will struggle with multi-step training pipelines. It is fine for exploration and script drafting, but for serious agent loops, you will want something with more reasoning headroom.
# Understanding How ML Intern Works
You do not need to memorize the architecture, but it helps to know why the agent sometimes pauses and asks you to approve something. The agent runs an iterative loop of up to 300 turns by default. The flowchart below gives a rough idea of what happens on each call.

How ML Intern processes each call
One of ML Intern's biggest strengths is the number of tools it can use out of the box. Built-in tools cover the HF ecosystem, including docs, datasets, repositories, papers, and jobs, plus GitHub search, local file operations, planning helpers, and anything you attach through Model Context Protocol (MCP)**. There is even a doom loop detector that catches repeated tool calls with the same arguments, which is a familiar problem if you have used coding agents before.
Every session can auto-upload to a private dataset on your Hub account ({username}/ml-intern-sessions) in a format the Agent Trace Viewer understands. These traces are especially useful for debugging because they let you inspect every reasoning step the agent took. If something goes wrong, you can open the session in the Agent Trace Viewer and see exactly where the agent made a poor decision.
You can also control how traces are shared during a session:
/share-traces private
/share-traces publicOr you can disable trace uploads entirely through the configuration file if you do not want to save session history.
# Avoiding Common Mistakes
- Be specific with your prompts. “Fine-tune llama” is vague. “Fine-tune meta-llama/Llama-3.2-1B on imdb with LoRA, max 1 epoch, do not push to Hub” is better.
- Watch the approvals. Training jobs cost money. Sandboxes cost money. The agent will ask, so do not blindly approve everything on your first run.
- Set --max-iterations if you are experimenting. The default limit of 300 iterations is great for complex tasks but can waste compute during testing.
- Check your traces. When something strange happens, your private session dataset on the Hub is the black box recorder.
# Taking the Next Steps
**
ML Intern will not replace your judgment. You still need to read the training logs, sanity-check the evaluation, and decide whether 32% on GPQA is actually what you wanted. But if you have ever stared at a blank train.py wondering where to start, having an intern who already knows the Hub is a strong first step.
Run ml-intern, give it something small, and see what it does. That is the game at the beginning. A few practical next steps:
- Explore the GitHub repository. Browse the source code, check out examples, and stay current with new features and improvements.
- Create your own custom tools. ML Intern is built to be extensible. You can add your own tools by modifying the agent/core/tools.py file and reinstalling the package:
uv tool install -e . --force- Connect MCP servers. If you are using MCP, you can attach external tools and services by updating the configs/cli_agent_config.json file. Environment variables such as ${YOUR_TOKEN} are automatically loaded from your .env file.
- Enable Slack notifications. Set SLACK_BOT_TOKEN and SLACK_CHANNEL_ID if you want ping-when-done alerts.
Kanwal Mehreen** is a machine learning engineer and a technical writer with a profound passion for data science and the intersection of AI with medicine. She co-authored the ebook "Maximizing Productivity with ChatGPT". As a Google Generation Scholar 2022 for APAC, she champions diversity and academic excellence. She's also recognized as a Teradata Diversity in Tech Scholar, Mitacs Globalink Research Scholar, and Harvard WeCode Scholar. Kanwal is an ardent advocate for change, having founded FEMCodes to empower women in STEM fields.
関連記事
今日のまとめ
AI日報で今日の重要ニュースをまとめ読み