Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ recursive-include dataflow *.sh
recursive-include dataflow *.txt

# 包含样例文件夹下所有类型的文件
# 样例文件夹路径为dataflow/exaple
recursive-include dataflow/example */
# 样例文件夹路径为dataflow/example
recursive-include dataflow/example *

# 包含顶层文档文件
include README.md
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 8 additions & 1 deletion dataflow/example/MultimodalKGPipeline/input.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
[
{
"raw_chunk": "Tesla unveiled the Cybertruck at a product event. Elon Musk appeared on stage during the launch presentation. The presentation focused on electric vehicle design and manufacturing.",
"img_dict": {}
"img_dict": {
"img_cybertruck": "../example_data/MultimodalKGPipeline/images/cyber.jpg",
"img_musk_stage": "../example_data/MultimodalKGPipeline/images/musk.jpg"
},
"vis_url": [
"../example_data/MultimodalKGPipeline/images/cyber.jpg",
"../example_data/MultimodalKGPipeline/images/musk.jpg"
]
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ def _extract_vis_urls(self, entities, vis_triples, img_dict):

for vt in vis_triples:

subj_match = re.search(r"<subj>\s*(.+?)\s*(?=<rel>)", vt)
obj_match = re.search(r"<obj>\s*(.+?)\s*$", vt)
subj_match = re.search(r"<subj>\s*(.+?)\s*(?=<obj>)", vt)
obj_match = re.search(r"<obj>\s*(.+?)\s*(?=<rel>)", vt)

if not subj_match or not obj_match:
continue
Expand Down Expand Up @@ -283,7 +283,7 @@ def run(

for vt in vis_triples:

subj_match = re.search(r"<subj>\s*(.+?)\s*(?=<rel>)", vt)
subj_match = re.search(r"<subj>\s*(.+?)\s*(?=<obj>)", vt)

if subj_match:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import re
from typing import List, Dict, Any
from tqdm import tqdm

Expand Down Expand Up @@ -115,15 +116,24 @@ def run(
all_qas = []

for _, row in tqdm(df.iterrows(), total=len(df), desc="Generating QA"):
# 构建 img_dict: key 从 vis_triple 中抽取图片ID, value 从 vis_url
# 构建 img_dict: key 从 vis_triple 中按首次出现顺序去重抽取图片ID, value 从 vis_url
# 注意: vis_url 在 step4 中已按首次出现顺序去重, 所以这里 img_id 也按首次出现顺序去重才能正确配对
img_dict = {}
vis_url_list = row.get(input_key, [])
vis_triple_list = row.get("vis_triple", [])

# 提取图片ID对应 URL
for triple, url in zip(vis_triple_list, vis_url_list):
# triple 格式: "<subj> X <rel> <obj> img_ID"
img_id = triple.strip().split()[-1]
ordered_img_ids = []
seen_img_ids = set()
for triple in vis_triple_list:
m = re.search(r"<obj>\s*(.+?)\s*(?=<rel>)", triple)
if not m:
continue
img_id = m.group(1).strip()
if img_id not in seen_img_ids:
seen_img_ids.add(img_id)
ordered_img_ids.append(img_id)

for img_id, url in zip(ordered_img_ids, vis_url_list):
img_dict[img_id] = url

subgraph = row.get(input_key_meta, [])
Expand Down
Loading