forked from PaddlePaddle/PaddleMIX
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[wip] add mix scheme (PaddlePaddle#664)
## PaddleMIX统一多模数据格式 1. [x] 纯文 2. [x] 单图 3. [x] 多图 4. [x] interleaved 5. [ ] 音频 6. [ ] 视频 ## 功能 1. [x] `MIX`格式定义和检查 2. [x] `MM`格式到`MIX`格式转换Op --- ## 特殊字段 1. [x] `images <-> <image>id</image>` 2. [ ] `audios <-> <audio>id</audio>` 3. [ ] `videos <-> <video>id</video>` ``` [ { 'id': '000002b66c9c498e', 'images': [ { 'id': 0, 'url': 'train/000002b66c9c498e.jpg', 'heigh': 100, 'width': 100, }, { 'id': 1, 'url': 'train/000002b66c9c498e.jpg', 'heigh': 100, 'width': 100, }, ], 'conversations': [ { 'from': 'user', 'value': '<image>id</image><image>id</image> xxxx' }, { 'from': 'assistant', 'value': 'xxx' }, { 'from': 'user', 'value': 'xxxx <image>id</image>' }, { 'from': 'assistant', 'value': 'xxx' } ], }, ] ```
- Loading branch information
Showing
9 changed files
with
194 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
from ._info import info, head | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
from ._h5 import from_h5, check_h5, export_h5 | ||
from ._schema import convert_schema |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
from ...core import T | ||
from ...core import SCHEMA, is_valid_schema | ||
|
||
|
||
def convert_schema( | ||
item: T, | ||
in_schema: SCHEMA=SCHEMA.MM, | ||
out_schema: SCHEMA=SCHEMA.MIX | ||
)-> T: | ||
"""convert scheme | ||
""" | ||
if in_schema == out_schema: | ||
return item | ||
|
||
# MM <-> MIX | ||
elif in_schema == SCHEMA.MM and out_schema == SCHEMA.MIX: | ||
return _convert_mm_mix(item) | ||
|
||
else: | ||
raise NotImplementedError('') | ||
|
||
|
||
def _convert_mm_mix(item): | ||
if 'image' in item: | ||
images = [{ | ||
'id': 0, | ||
'url': item['image'], | ||
}] | ||
else: | ||
images = None | ||
|
||
conversations = [] | ||
for conv in item['conversations']: | ||
if conv['from'] == 'human': | ||
role = 'user' | ||
if 'image' in item: | ||
if '<image>' in conv['value']: | ||
value = conv['value'].replace('<image>', '<image>0</image>') | ||
else: | ||
value = '<image>0</image>\n' + conv['value'] | ||
else: | ||
value = conv['value'] | ||
else: | ||
role = 'assistant' | ||
value = conv['value'] | ||
|
||
conversations.append({ | ||
'from': role, | ||
'value': value, | ||
}) | ||
|
||
newitem = { | ||
'id': item['id'], | ||
'images': images, | ||
'conversations': conversations | ||
} | ||
return newitem | ||
|