开发者社区 > ModelScope模型即服务 > 正文

用ModelScope微调训练成功的模型来进行单模态地址和多模态地址预测,此时发生错误,怎么解决?

"推理预测函数:
def validate_or_predict(model_dir):
print('gpu count:',torch._C._cuda_getDeviceCount())
print(modelscope.version)

#model = Model.from_pretrained(model_dir)
#print(model.cfg)
#preprocessor = Preprocessor.from_pretrained('some model')

task = Tasks.text_ranking
#model = 'damo/mgeo_geographic_textual_similarity_rerank_chinese_base'
# 多模态输入,包括需要排序的文本以及地理信息
multi_modal_inputs = {
    ""source_sentence"": ['杭州余杭东方未来学校附近世纪华联商场(金家渡北苑店)'],
    ""first_sequence_gis"": [[[13159, 13295, 13136, 13157, 13158, 13291, 13294, 74505, 74713, 75387, 75389, 75411], [3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4], [3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4], [[1254, 1474, 1255, 1476], [1253, 1473, 1256, 1476], [1247, 1473, 1255, 1480], [1252, 1475, 1253, 1476], [1253, 1475, 1253, 1476], [1252, 1471, 1254, 1475], [1254, 1473, 1256, 1475], [1238, 1427, 1339, 1490], [1238, 1427, 1339, 1490], [1252, 1474, 1255, 1476], [1252, 1474, 1255, 1476], [1249, 1472, 1255, 1479]], [[24, 23, 15, 23], [24, 28, 15, 18], [31, 24, 22, 22], [43, 13, 37, 13], [43, 6, 35, 6], [31, 32, 22, 14], [19, 30, 9, 16], [24, 30, 15, 16], [24, 30, 15, 16], [29, 24, 20, 22], [28, 25, 19, 21], [31, 26, 22, 20]], ""120.08802231437534,30.343853313981505""]],
    ""sentences_to_compare"": [
        '良渚街道金家渡北苑42号世纪华联超市(金家渡北苑店)',
        '金家渡路金家渡中苑南区70幢金家渡中苑70幢',
        '金家渡路140-142号附近家家福足道(金家渡店)'
        ],
    ""second_sequence_gis"": [
        [[13083, 13081, 13084, 13085, 13131, 13134, 13136, 13147, 13148], [3, 3, 3, 3, 3, 3, 3, 3, 3], [3, 4, 4, 4, 4, 4, 4, 4, 4], [[1248, 1477, 1250, 1479], [1248, 1475, 1250, 1476], [1247, 1478, 1249, 1481], [1249, 1479, 1249, 1480], [1249, 1476, 1250, 1476], [1250, 1474, 1252, 1478], [1247, 1473, 1255, 1480], [1250, 1478, 1251, 1479], [1249, 1478, 1250, 1481]], [[30, 26, 21, 20], [32, 43, 23, 43], [33, 23, 23, 23], [31, 13, 22, 13], [25, 43, 16, 43], [20, 33, 10, 33], [26, 29, 17, 17], [18, 21, 8, 21], [26, 23, 17, 23]], ""120.08075205680345,30.34697777462197""],
        [[13291, 13159, 13295, 74713, 75387, 75389, 75411], [3, 3, 3, 4, 4, 4, 4], [3, 4, 4, 4, 4, 4, 4], [[1252, 1471, 1254, 1475], [1254, 1474, 1255, 1476], [1253, 1473, 1256, 1476], [1238, 1427, 1339, 1490], [1252, 1474, 1255, 1476], [1252, 1474, 1255, 1476], [1249, 1472, 1255, 1479]], [[28, 28, 19, 18], [22, 16, 12, 16], [23, 24, 13, 22], [24, 30, 15, 16], [27, 20, 18, 20], [27, 21, 18, 21], [30, 24, 21, 22]], ""120.0872539617001,30.342783672056953""],
        [[13291, 13290, 13294, 13295, 13298], [3, 3, 3, 3, 3], [3, 4, 4, 4, 4], [[1252, 1471, 1254, 1475], [1253, 1469, 1255, 1472], [1254, 1473, 1256, 1475], [1253, 1473, 1256, 1476], [1255, 1467, 1258, 1472]], [[32, 25, 23, 21], [26, 33, 17, 33], [21, 19, 11, 19], [25, 21, 16, 21], [21, 33, 11, 33]], ""120.08839673752281,30.34156156893651""]
        ]
    }

# 单模态输入,只包括需要排序的文本
single_modal_inputs = {
    ""source_sentence"": ['杭州余杭东方未来学校附近世纪华联商场(金家渡北苑店)'],
    ""sentences_to_compare"": [
        '良渚街道金家渡北苑42号世纪华联超市(金家渡北苑店)',
        '金家渡路金家渡中苑南区70幢金家渡中苑70幢',
        '金家渡路140-142号附近家家福足道(金家渡店)'
        ]
    }

# 模型可接受多模态输入
pipeline_ins = pipeline(
    task=task, model=model_dir)
print(pipeline_ins(input=multi_modal_inputs))
# 输出
# {'scores': [0.9997552633285522, 0.027718106284737587, 0.03500296175479889]}

# 模型可接受单模态输入
pipeline_ins = pipeline(
task=task, model=model_dir)
print(pipeline_ins(input=single_modal_inputs))
# 输出
# {'scores': [0.9986912608146667, 0.0075200702995061874, 0.014017169363796711]}       

操作过程是先COPY覆盖,然后自定义训练,经修改后微调训练成功.然后再用ModelScope微调训练成功的模型来进行单模态地址和多模态地址预测,此时发生错误,怎么解决?"

展开
收起
小小爱吃香菜 2024-06-26 08:30:39 31 0
1 条回答
写回答
取消 提交回答
  • neg_sample = 19不能改成neg_sampel=1 此回答整理自钉群“魔搭ModelScope开发者联盟群 ①”

    2024-06-28 19:58:47
    赞同 1 展开评论 打赏

ModelScope旨在打造下一代开源的模型即服务共享平台,为泛AI开发者提供灵活、易用、低成本的一站式模型服务产品,让模型应用更简单!欢迎加入技术交流群:微信公众号:魔搭ModelScope社区,钉钉群号:44837352

相关电子书

更多
视觉AI能力的开放现状及ModelScope实战 立即下载
ModelScope助力语音AI模型创新与应用 立即下载
低代码开发师(初级)实战教程 立即下载