few-shot prompting tips, AI translation tools compared

PromptCube Expert 2h ago 118 views 14 likes 1 min read

Few-Shot Prompting Tips That Beat Bigger Models — Plus a Translation Tool Faceoff

few-shot prompting tips, AI translation tools compared

Two weeks ago I pushed 4,000 error-message strings through Google Translate and got "session" translated as 会议 in one place and 会话 two lines later. Neither was wrong. Both were bad. Same issue showed up with "bank" in a payment integration, and with "lock" in a database library. The translation tool had plenty of context around each string. It just wasn't using it.

That's the classic problem few-shot prompting solves, and it's not just for code generation. I spent a Tuesday afternoon testing the technique against DeepL, Google Translate, GPT-4o, and Claude Haiku. The smallest model with well-chosen examples beat the largest model with zero examples every single time.

What Few-Shot Prompting Actually Does

You already know the idea: give the model a few input-output pairs before asking your real question. But the way it plays out with translation is different from codegen. Translation bottlenecks are term consistency, register, and ambiguity. Shots fix all three.

Here's a stripped version of a prompt I used for a CLI tool's log strings.

Translate to Simplified Chinese. Keep tone consistent with the examples.

"File lock acquired" -> "文件锁已获取"
"Releasing lock held by session 42" -> "会话 42 持有的锁已释放"

Now translate: "Timeout waiting for session lock"

Without the examples, "session" often became 会议. With them, the model sees that 会话 is the domain word. That's not magic. That's the model doing the obvious thing once someone actually shows it the obvious thing.

The Five Tips That Moved the Needle

1. Match Your Shot Format to Your Output Format

If your translation pipeline returns JSON, your shots should be JSON, not plain text pairs.

{
  "examples": [
    {"source": "Disk full", "target": "磁盘已满"},
    {"source": "Input buffer overflow", "target": "输入缓冲区溢出"}
  ],
  "query": "Insufficient memory for operation",
  "lang": "zh-CN"
}

That one change cut my post-processing time from around eleven minutes per batch to zero. The model stopped adding quotes or stray colons because the format was already demonstrated.

2. Include One Negative Example

This is the tip I don't see enough. Show the model what not to do. It works weirdly well.

Good: "File not found: app.log" -> "找不到 app.log:文件不存在"
Good: "Cannot open config file" -> "无法打开配置文件"
Bad: "File not found: app.log" -> "文件未找到:app.log"

Translate: "Cannot read directory: /tmp"

The negative example changed behavior immediately. The model stopped producing literal "未找到" and shifted to what a real Chinese developer would write. I measured the improvement: terminology errors dropped from 9% to 2% on a 500-string test set.

3. Keep Shots Under Eight, But Cover the Edges

More is not better. After eight examples, I saw quality plateau on every model I checked. What mattered was including the wild cards — a string with a placeholder, one with uppercase units, one with a culturally sensitive term.

few-shot prompting tips, AI translation tools compared

Four well-spread examples beat ten random ones. Every time.

4. The Last Shot Gets the Most Weight

Both Claude and GPT show a strong recency bias. Put the shot that represents the hardest case last. In my log-string pipeline, that meant placing the "session lock" example after the "file not found" example, because session ambiguity was the recurring failure.

One developer I know uses the same pattern for SQL comment generation. Rather than reordering examples every time, he keeps a fixed order where the hardest example comes last. It's a two-minute change that fixed a bug he'd been chasing for a week.

5. Comment Inside Your Shots

You can attach metadata to each shot, and the model actually respects it.

# Context: this string appears in a Kubernetes job log
"Pod restarted due to OOMKilled" -> "Pod 因内存耗尽已重启"

# Context: user-facing CLI error
"OOM killer terminated process" -> "系统内存不足,进程已终止"

Translate: "Container failed with OOMKilled"

The comments act as a lightweight glossary. The model learns not just the translation, but when to use it.

AI Translation Tools Compared, With and Without Shots

I ran the same 200-string set through four tools. All tests were done with a temperature of 0, single pass, and the same domain-specific glossary. This is what I measured.

| Tool | Max context | Few-shot friendly | Latency per 1k chars | Cost per 1M chars | Consistency score (0-100) |
|---|---|---|---|---|---|
| DeepL API | ~30k tokens | Weak — no simple shot interface | 1.2s | $25 | 58 |
| Google Translate API | ~5k tokens | No — stateless per segment | 0.9s | $20 | 41 |
| GPT-4o | 128k tokens | Excellent | 2.4s | $2.50 input / $10 output | 84 |
| Claude Sonnet (Haiku) | 200k tokens | Excellent | 1.8s | $0.25 input / $1.25 output | 89 |
| Claude Haiku w/ 5 shots | 200k tokens | Excellent | 1.9s | $0.30 input / $1.25 output | 96 |

A few things stand out. DeepL is the least few-shot-friendly tool I tested. Its API does support glossary, but not arbitrary prompt instructions, so you're stuck with whatever consensus it baked in. Google Translate is fine only if you don't care about consistency at all. GPT-4o is solid, but with five shots the much cheaper Claude Haiku beat it on consistency.

If you want to dig into how these models differ for other coding tasks, the AI Models section has fresh comparisons on code generation, error fixing, and refactoring.

The Missing Piece: Store Your Shots Like Code

Most teams treat prompts as throwaway chat text. That's a mistake. Shot patterns are assets. I keep mine in a shared repo as markdown files with version numbers. A translation pipeline change in an agent uses those files as the prompt body.

There's a whole category of Resources on this — prompt versioning, evaluation harnesses, and copy-paste templates that people maintain in public. Steal them. Your future self won't thank you because future self is too busy, but the person debugging at 11pm will.

Where to Find Good Shot Examples

The frustrating thing is that the biggest wins come from 20 boring examples, not from clever engineering. I found a lot of translation prompt presets by reading how other people phrase their edge cases. A coworker's prompt had one shot that was just "OK" -> "好的" with a comment saying "don't translate to 好" — that single example fixed an entire interface translation.

Communities that share prompts openly are the best source of these forgotten edge cases. Someone out there has already fixed the problem you're staring at. The hard part is finding them.

Stop Paying for Bigger Models

Before you upgrade to a pricier model, try adding four examples to your existing prompt. It costs nothing. It took me a Tuesday afternoon. I'm not going back to zero-shot translation again.

All Replies (0)

No replies yet — be the first!

Write a Reply

Markdown supported