LLM-as-RNN: 자연어 메모리로 순차 예측을 개선하는 Recurrent 추론 프레임워크
LLM-as-RNN: A Recurrent Language Model for Memory Updates and Sequence Prediction
TL;DR Highlight
파라미터 수정 없이 LLM을 RNN처럼 동작하게 만들어, 매 스텝마다 자연어 메모리를 업데이트해 장기 시퀀스 예측 정확도를 높이는 추론 전용 프레임워크.
Who Should Read
LLM을 활용해 의료/금융/날씨 같은 시계열 데이터를 예측하거나 장기 대화 맥락을 관리하는 AI 엔지니어. 특히 컨텍스트 누적 방식의 'lost-in-the-middle' 문제나 에러가 계속 이어지는 현상을 겪고 있는 개발자에게 유용하다.
Core Mechanics
- 기존 LLM은 과거 실수를 고칠 수 없는 append-only 컨텍스트를 쓰는데, LLM-as-RNN은 매 스텝마다 system prompt 요약본을 피드백 기반으로 덮어써서 에러를 수정함
- 3단계 루프로 동작: (1) 이전 메모리 + 현재 입력으로 예측 생성 → (2) 정답과 비교해 자연어 피드백 생성 → (3) 피드백을 반영해 메모리 재작성
- 전체 히스토리를 다 때려넣는 FHC(Full History Concatenation) 방식보다 오히려 성능이 높음 — 정보가 많아도 잘 큐레이션된 압축 메모리가 더 유리
- 작은 모델(Llama-3.2-3B + LLM-as-RNN)이 70B 모델의 FHC 방식을 이김 — 메모리 업데이트 루프가 모델 크기를 일부 보완
- ground truth 없이 LLM-as-a-Judge로 자기 피드백을 쓸 수도 있음 (성능은 약간 낮지만 zero-shot보다는 훨씬 좋음)
- 메모리가 자연어라 사람이 읽을 수 있어서, 모델이 왜 그런 예측을 했는지 추적하고 감사(audit)하기 쉬움
Evidence
- MIMIC-IV 임상 데이터셋에서 Acc@1 기준 최강 베이스라인(MemPrompt) 대비 12.6% 포인트 향상 (0.5175 → 0.6434, Gemma-3-27B 기준)
- S&P 500 금융 예측에서 MSE 기준 MemPrompt 대비 6.6% 개선 (4.090 → 3.821, GPT-oss-120B 기준)
- Llama-3.1-70B + FHC(Acc@1: 0.4126)를 Llama-3.2-3B + LLM-as-RNN(Acc@1: 0.4545)이 능가 — 파라미터 23배 차이를 메모리 구조가 역전
- 오류 발생 후 다음 스텝에서 54.8% 확률로 스스로 수정 (나머지 45.2%는 에러 지속)
How to Apply
- 장기 대화나 반복 작업 에이전트에서 전체 히스토리를 컨텍스트에 쌓는 대신, system prompt에 '압축 메모리' 섹션을 두고 매 턴마다 피드백을 반영해 덮어쓰는 방식으로 교체해볼 수 있다
- 정답이 있는 supervised 시나리오(예: 특정 포맷 체크, 테스트 통과 여부)면 ground truth 피드백을, 정답이 없는 경우엔 LLM-as-a-Judge로 자기비판 루프를 구성하면 된다
- 컨텍스트 예산 λ는 4096 토큰 정도가 성능/비용 균형점 — 8192로 늘려도 개선 폭이 작아서 4096을 기본값으로 쓰는 게 합리적
Code Example
# LLM-as-RNN 핵심 루프 예시 (pseudo-code)
system_memory = "" # h0: 초기 메모리 상태
for step, (observation, ground_truth) in enumerate(sequence):
# Phase 1: Contextualization — 메모리 + 현재 입력으로 예측
prediction = llm.generate(
system=f"""당신은 순차 예측 AI입니다.
[학습된 메모리]
{system_memory}""",
user=f"현재 관측값: {observation}\n예측하세요."
)
# Phase 2: Reflection — 피드백 생성
if ground_truth: # supervised mode
feedback = f"오류: 예측={prediction}, 정답={ground_truth}. 무엇을 놓쳤는지 분석하세요."
else: # open-ended mode (LLM-as-a-Judge)
feedback = llm.generate(
user=f"예측: {prediction}\n품질 기준: {quality_criteria}\n비판적으로 평가하세요."
)
# Phase 3: Memory Update — 피드백 반영해 메모리 재작성
system_memory = llm.generate(
user=f"""현재 메모리:
{system_memory}
이번 스텝 요약: {observation} → {prediction}
피드백: {feedback}
위 내용을 반영해 메모리를 업데이트하세요.
규칙: 틀린 패턴은 수정하고, 맞은 패턴은 강화하세요. 200단어 이내."""
)Terminology
Related Resources
Original Abstract (Expand)
Large language models are strong sequence predictors, yet standard inference relies on immutable context histories. After making an error at generation step t, the model lacks an updatable memory mechanism that improves predictions for step t+1. We propose LLM-as-RNN, an inference-only framework that turns a frozen LLM into a recurrent predictor by representing its hidden state as natural-language memory. This state, implemented as a structured system-prompt summary, is updated at each timestep via feedback-driven text rewrites, enabling learning without parameter updates. Under a fixed token budget, LLM-as-RNN corrects errors and retains task-relevant patterns, effectively performing online learning through language. We evaluate the method on three sequential benchmarks in healthcare, meteorology, and finance across Llama, Gemma, and GPT model families. LLM-as-RNN significantly outperforms zero-shot, full-history, and MemPrompt baselines, improving predictive accuracy by 6.5% on average, while producing interpretable, human-readable learning traces absent in standard context accumulation.