开发者社区 > ModelScope模型即服务 > 自然语言处理 > 正文

为什么我的运行的 'damo/nlp_convai_text2sql_pre连简单的sum都不行

屏幕截图 2023-04-22 151349.png

model_id = 'damo/nlp_convai_text2sql_pretrain_cn'
model = Model.from_pretrained(model_id)
tokenizer = BertTokenizer(os.path.join(model.model_dir, ModelFile.VOCAB_FILE))

db = Database(tokenizer=tokenizer,
              # table_file_path=os.path.join('/home/django/users.json'),
              table_file_path='/home/django/order_item.json',
              syn_dict_file_path=os.path.join(model.model_dir, 'synonym.txt'),
              is_use_sqlite=True)
preprocessor = TableQuestionAnsweringPreprocessor(model_dir=model.model_dir, db=db)
pipelines = [
    pipeline(
        Tasks.table_question_answering,
        model=model,
        preprocessor=preprocessor,
        db=db)
]
test_case = {
    'utterance': [['我一共购买了多少镀锌钢管', 'material_item']]
}

for pipeline in pipelines:
    historical_queries = None
    for question, table_id in test_case['utterance']:
        output_dict = pipeline({
            'question': question,
            'table_id': table_id,
            'history_sql': historical_queries
        })[OutputKeys.OUTPUT]
        print('question', question)
        print('sql text:', output_dict[OutputKeys.SQL_STRING])
        print('sql query:', output_dict[OutputKeys.SQL_QUERY])
        print('sql query:', output_dict[OutputKeys.QUERT_RESULT])
        print()
        historical_queries = output_dict[OutputKeys.HISTORY]
class Command(BaseCommand):
    help = 'Generate JSON data for OrderItem'

    def handle(self, *args, **options):
        header_id = ['id', 'material_name', 'sku', 'purchase',
                     'unit',
                     'order_name',
                     'user',
                     'time']
        header_name = ["编码", "材料名称", "规格", "购买数量", "单位", "材料单名称", "采购者", '时间']
        header_types = ["text", "text", "text", "number", "text", "text", "text", "date"]
        header_units = ["", "", "", "个", "", "", "", ""]
        header_attribute = ["PRIMARY", "MODIFIER", "MODIFIER", "MODIFIER", "MODIFIER", "MODIFIER", "MODIFIER",
                            "MODIFIER"]
        rows = []
        order_items = OrderItem.objects.all()
        for o in order_items:
            rows.append([
                str(o.id),
                remove_special_chars(o.material.name),
                remove_special_chars(o.material.sku),
                o.buy_num,
                remove_special_chars(o.material.unit),
                # str(o.order.id),
                remove_special_chars(o.order.name),
                # str(o.order.created_by.id),
                remove_special_chars(o.order.created_by.name),
                o.order.created_time.date().isoformat(),
            ])
        data = {
            "table_id": "order_item",
            "table_name": "采购明细",
            "header_id": header_id,
            "header_name": header_name,
            "header_types": header_types,
            "header_units": header_units,
            "header_attribute": header_attribute,
            "rows": rows
        }
        with open('order_item.json', 'w') as f:
            json.dump(data, f, ensure_ascii=False)

        self.stdout.write(json.dumps(data))

展开
收起
xxgzzp 2023-04-22 15:25:23 466 0
0 条回答
写回答
取消 提交回答

包含命名实体识别、文本分类、分词、关系抽取、问答、推理、文本摘要、情感分析、机器翻译等多个领域

相关产品

  • 自然语言处理
  • 热门讨论

    热门文章

    相关电子书

    更多
    SQL Server在电子商务中的应用与实践 立即下载
    GeoMesa on Spark SQL 立即下载
    原生SQL on Hadoop引擎- Apache HAWQ 2.x最新技术解密malili 立即下载