Skip to content

[資料正確性] 多篇貼文一起分析時,所有 prediction 都會被歸到最新一篇貼文 #23

Description

@timshan

問題說明

目前 analyzePosts() 可以一次分析多篇貼文,但 LLM 輸出的 mentionedTargets 沒有帶來源貼文資訊,例如 post_idpostIndex 或原始時間戳。

之後 recordPredictions() 會直接使用:

const latestPost = posts[0];

並把所有 target 都寫成:

post_id: latestPost.id,
post_url: latestPost.url,
created_at: latestPost.timestamp,

基準價格也同樣使用:

basePrice = await getBasePrice(
  stock.code,
  stock.market,
  latestPost.timestamp,
);

這代表只要同一批分析包含兩篇以上、而且不同貼文各自提到不同標的,最後所有 prediction 都會被歸到 posts[0],也就是最新那篇貼文。

相關檔案:

  • src/analyze.ts
  • src/tracker.ts
  • src/index.ts

範例情境

假設一次抓到兩篇新貼文:

貼文 A(10:00):提到台積電
貼文 B(09:00):提到旺宏

傳給 analyzePosts() 時,LLM 可能產生:

{
  "mentionedTargets": [
    { "name": "台積電" },
    { "name": "旺宏" }
  ]
}

但目前 output schema 無法表示「台積電來自貼文 A、旺宏來自貼文 B」。

接著 recordPredictions() 會把兩個 target 都綁到:

貼文 A 的 post_id
貼文 A 的 post_url
貼文 A 的 timestamp

因此旺宏 prediction 的來源貼文與基準價格時間都會錯誤。

實際影響

這不只是顯示問題,會影響後續回測資料的正確性:

  1. post_id / post_url 指到錯的貼文。
  2. created_at 使用錯誤的發文時間。
  3. getBasePrice() 會依錯誤 timestamp 取得基準價格。
  4. 如果兩篇貼文跨交易時段、跨日,價格誤差可能更明顯。
  5. 後續用公開資料集計算 prediction 成效時,資料 lineage 會失真。

預期結果

每一個 prediction 都應能明確追溯到真正產生該判斷的原始貼文。

例如 LLM output 可以增加來源索引:

{
  "mentionedTargets": [
    {
      "name": "台積電",
      "postIndex": 0
    },
    {
      "name": "旺宏",
      "postIndex": 1
    }
  ]
}

或更直接在輸入中提供穩定 ID,讓模型回傳:

{
  "postId": "fb_xxx"
}

接著 recordPredictions() 應依各 target 的來源貼文取得:

post_id
post_url
timestamp
base_price

可能的修正方向

方案一:每個 target 增加 postIndex

在 prompt 中明確要求模型回傳來源貼文編號,實作成本較低。

方案二:每篇貼文帶 postId

postId 放進 analyzePosts() 的 input 與 prompt,要求模型直接回傳來源 ID。這種方式比 array index 更穩定,也比較適合未來資料結構調整。

方案三:逐篇分析

如果跨貼文推理不是必要功能,也可以每篇貼文各自跑分析,再於上層合併結果。不過成本與 LLM request 數會增加。

建議增加測試案例:兩篇貼文各自提到不同股票,確認寫入 DB 後每個 prediction 的 post_idcreated_at 都對應到正確來源。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions