MCPcopy Create free account
hub / github.com/EmbodiedGPT/EmbodiedGPT_Pytorch / format_inputs

Function format_inputs

robohusky/base_dataset.py:50–83  ·  view source on GitHub ↗
(sources)

Source from the content-addressed store, hash-verified

48 return transform
49
50def format_inputs(sources):
51 # Apply prompt templates
52 conv = get_conv_template("husky").copy()
53 roles = {"human": conv.roles[0], "gpt": conv.roles[1]}
54 conversations = []
55
56 for i, source in enumerate(sources):
57 if roles[source[0]["from"]] != conv.roles[0]:
58 # Skip the first one if it is not from human
59 source = source[1:]
60
61 conv.messages = []
62 for j, sentence in enumerate(source):
63 role = roles[sentence["from"]]
64 assert role == conv.roles[j % 2], f"{i}"
65 # vision is only supported for the human input
66 if role == conv.roles[0]:
67 value = sentence["value"]
68 if "<image>" in value:
69 if value.endswith("\n<image>"):
70 value = "<image>\n" + value.replace("\n<image>", "")
71 image_query = DEFAULT_IMG_START_TOKEN + DEFAULT_IMG_END_TOKEN
72 sentence["value"] = value.replace("<image>", image_query)
73
74 elif "<video>" in value:
75 if value.endswith("\n<video>"):
76 value = "<video>\n" + value.replace("\n<video>", "")
77 video_query = DEFAULT_VIDEO_START_TOKEN + DEFAULT_VIDEO_END_TOKEN
78 sentence["value"] = value.replace("<video>", video_query)
79
80 conv.append_message(role, sentence["value"])
81 conversations.append(conv.get_prompt())
82
83 return conversations, conv
84
85def process_func(examples, tokenizer, max_seq_length):
86 conversations, conv = format_inputs(examples['conversations'])

Callers 1

process_funcFunction · 0.70

Calls 4

get_conv_templateFunction · 0.90
copyMethod · 0.80
append_messageMethod · 0.80
get_promptMethod · 0.80

Tested by

no test coverage detected