Sitemap
Daisuke Majima (MLBoy)

Daisuke Majima (MLBoy)

On-device AI. Core AI model zoo (60+ models) · devicemark iPhone LLM leaderboard · author of "The Art of Core AI" → github.com/john-rocky

AI Detective ERNIE: Who’s the Liar? — Challenge yourself with the 3-player and 4-player puzzles!

3 min readOct 8, 2025

--

Introduction

ERNIE-4.5–21B-A3B-Thinking , released by Baidu , is a large-scale language model known for its strengths in long-text comprehension and complex reasoning.
To test its performance, we used the “ Liar and Truthteller “ puzzle. The condition was that exactly one person must tell the truth each day.

experiment

Run the 3-player puzzle

puzzle_3 = """三人 A/B/C がいて、毎日必ず一人だけが真実を述べ、残りは嘘をつく。
A:「Bは嘘をついた」
B:「Cは嘘をついた」
C:「AとBは両方嘘だ」
今日真実を述べたのは誰?"""
prompt = build_prompt(puzzle_3)
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
_ = model.generate(
**inputs,
max_new_tokens=512,
temperature=0.2,
top_p=0.9,
do_sample=True,
streamer=streamer
)

Output results

{
"answer": "B",
"steps_bulleted": [
"Aが真だと矛盾",
"Bが真だとAは嘘、Cは嘘で一貫",
"Cが真だと矛盾"
],
"self_check": "Only one truth-teller holds when B is true; other cases contradict."
}

Run the 4-player puzzle

puzzle_4 = """四人 A/B/C/D がいて、毎日必ず一人だけが真実を述べ、残りは嘘をつく。
A:「Bは嘘つき」
B:「Cは嘘つき」
C:「Dは嘘つき」
D:「Aは嘘つき」
今日真実を述べたのは誰?"""
prompt = build_prompt(puzzle_4)
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
_ = model.generate(
**inputs,
max_new_tokens=512,
temperature=0.2,
top_p=0.9,
do_sample=True,
streamer=streamer
)

Output results

{
"answer": "C",
"steps_bulleted": [
"Aが真だとCも真になり矛盾",
"Bが真だとDも真になり矛盾",
"Cが真だとDは嘘になり一貫",
"Dが真だと他と矛盾"
],
"self_check": "Only case C yields exactly one truth-teller; consistent."
}

What we learned from the experiment

-For each case, the flow of assumption → verification → checking for contradictions → conclusion emerges naturally.

・Specifying the output as JSON format makes it easy to use in articles and teaching materials.

- Even if the number of people increases, inference can be carried out without contradiction, and it remains stable even when scaled .

Recommended uses for ERNIE-4.5–21B

1. Education/teaching material creation : Automatically generate
math and logic puzzles with step-by-step explanations
. Can be used as “sample answers” for lessons and practice problems.

2. Check for inconsistencies in contracts and rule documents
- Automatically check whether “this condition contradicts this other condition.”
- Supports long context (128K tokens), so multi-page regulations and legal documents can be processed at once.

3. Reading comprehension and summary tasks : Extracting and organizing key points
from papers and technical documents. ・Strong in questions such as, “What conclusion can be logically derived from this premise?”

4. When incorporated as an explanation AI in mystery/game apps
and puzzle-solving games , it can provide players with “hints” and “solution processes.”
・The AI ​​can guide players through classic logic games like Knights & Naves and Zebra Puzzle with explanations.

Get Daisuke Majima (MLBoy)’s stories in your inbox

Join Medium for free to get updates from this writer.

5. Research and Analysis Support : A tool to assist
in reading research papers and survey reports and verifying the validity of causal relationships and logical development
. Convenient for organizing your thoughts in the “hypothesis → verification → counterexample confirmation” format.

procedure

Install the required libraries

!pip install -U "transformers>=4.54.0" accelerate torch --index-url https://download.pytorch.org/whl/cu121
!pip install -U sentencepiece

Load Model

from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer
import torch
model_id = "baidu/ERNIE-4.5-21B-A3B-Thinking"tokenizer = AutoTokenizer.from_pretrained(model_id, use_fast=True)
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype=torch.bfloat16, # bfloat16推奨
device_map="auto" # GPU自動割り当て
)
streamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)

Prompt Generation Function
Define a template function to use for logic puzzles.
Specifying that the answer be returned in JSON format makes it easier to write and analyze.

def build_prompt(puzzle_text):
system = (
"You are an expert puzzle solver. Solve step-by-step, verify, "
"then output a concise final answer as JSON with keys: "
"answer, steps_bulleted, self_check."
)
user = f"""[TASK]
{puzzle_text}
[REQUIREMENTS]
1) Think step-by-step to deduce facts.
2) Do not skip steps. Keep track of constraints.
3) After solving, run a brief self-consistency check.
4) Finally, output:
{{"answer": "...", "steps_bulleted": ["...","..."], "self_check": "OK or issues"}}
"""
return f"<|system|>\n{system}\n<|user|>\n{user}\n<|assistant|>\n"

Run the 3-player puzzle

puzzle_3 = """三人 A/B/C がいて、毎日必ず一人だけが真実を述べ、残りは嘘をつく。
A:「Bは嘘をついた」
B:「Cは嘘をついた」
C:「AとBは両方嘘だ」
今日真実を述べたのは誰?"""
prompt = build_prompt(puzzle_3)
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
_ = model.generate(
**inputs,
max_new_tokens=512,
temperature=0.2,
top_p=0.9,
do_sample=True,
streamer=streamer
)

Run the 4-player puzzle

puzzle_4 = """四人 A/B/C/D がいて、毎日必ず一人だけが真実を述べ、残りは嘘をつく。
A:「Bは嘘つき」
B:「Cは嘘つき」
C:「Dは嘘つき」
D:「Aは嘘つき」
今日真実を述べたのは誰?"""
prompt = build_prompt(puzzle_4)
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
_ = model.generate(
**inputs,
max_new_tokens=512,
temperature=0.2,
top_p=0.9,
do_sample=True,
streamer=streamer
)

summary

We asked ERNIE-4.5–21B-A3B-Thinking to solve two logic puzzles, one for three people (answer: B) and one for four people (answer: C), and it was able to arrive at the correct answer without any contradictions. This can be easily reproduced in Colab, and the answers are returned in JSON format, so you can use them directly in articles and teaching materials.

This model is

・Practice logic puzzles and math problems
・Check for contradictions in regulations and contracts
・Read and summarize long texts
・Apply to mystery games and educational apps

I felt that it was suitable for the following uses.

I’m a freelance engineer.
For business inquiries, please contact
rockyshikoku@gmail.com

I am developing an app using Core ML and
providing information related to machine learning.

Twitter
Medium
GitHub

--

--

Daisuke Majima (MLBoy)
Daisuke Majima (MLBoy)

On-device AI. Core AI model zoo (60+ models) · devicemark iPhone LLM leaderboard · author of "The Art of Core AI" → github.com/john-rocky