HuggingFace镜像/cogvlm2-llama3-chinese-chat-19B
模型介绍文件和版本分析
下载使用量0

CogVLM2

👋 微信 · 💡在线演示 · 🎈GitHub 页面 · 📑 论文

📍在 智谱AI开放平台 体验更大规模的 CogVLM 模型。

模型简介

我们推出了新一代的 CogVLM2 系列模型,并开源了两个基于 Meta-Llama-3-8B-Instruct 构建的模型。与上一代 CogVLM 开源模型相比,CogVLM2 系列开源模型有以下改进:

  1. 在 TextVQA、DocVQA 等多个基准测试中取得了显著改进。
  2. 支持 8K 内容长度。
  3. 支持高达 1344 * 1344 的图像分辨率。
  4. 提供了一个支持 中文和英文 的开源模型版本。

您可以在下表中查看 CogVLM2 家族开源模型的详细信息:

模型名称cogvlm2-llama3-chat-19Bcogvlm2-llama3-chinese-chat-19B
基础模型Meta-Llama-3-8B-InstructMeta-Llama-3-8B-Instruct
语言英文中文, 英文
模型大小19B19B
任务图像理解, 对话模型图像理解, 对话模型
文本长度8K8K
图像分辨率1344 * 13441344 * 1344

基准测试

我们的开源模型与上一代 CogVLM 开源模型相比,在许多列表中取得了良好的成绩。其出色的性能可以与一些非开源模型相媲美,如下表所示:

模型开源LLM 大小TextVQADocVQAChartQAOCRbenchVCR_EASYVCR_HARDMMMUMMVetMMBench
CogVLM1.1✅7B69.7-68.359073.934.637.352.065.8
LLaVA-1.5✅13B61.3--337--37.035.467.7
Mini-Gemini✅34B74.1-----48.059.380.6
LLaVA-NeXT-LLaMA3✅8B-78.269.5---41.7-72.1
LLaVA-NeXT-110B✅110B-85.779.7---49.1-80.5
InternVL-1.5✅20B80.690.983.872014.72.046.855.482.3
QwenVL-Plus❌-78.991.478.1726--51.455.767.0
Claude3-Opus❌--89.380.869463.8537.859.451.763.3
Gemini Pro 1.5❌-73.586.581.3-62.7328.158.5--
GPT-4V❌-78.088.478.565652.0425.856.867.775.0
CogVLM2-LLaMA3✅8B84.292.381.075683.338.044.360.480.5
CogVLM2-LLaMA3-Chinese✅8B85.088.474.778079.925.142.860.578.9

所有评价都是在不使用任何外部 OCR 工具的情况下获得的("仅像素")。

快速入门

以下是一个如何使用 CogVLM2 模型与模型聊天的简单示例。更多用例,请在我们 的 GitHub 中查找。

import torch
from PIL import Image
from transformers import AutoModelForCausalLM, AutoTokenizer

MODEL_PATH = "THUDM/cogvlm2-llama3-chinese-chat-19B"
DEVICE = 'cuda' if torch.cuda.is_available() else 'cpu'
TORCH_TYPE = torch.bfloat16 if torch.cuda.is_available() and torch.cuda.get_device_capability()[0] >= 8 else torch.float16

tokenizer = AutoTokenizer.from_pretrained(
    MODEL_PATH,
    trust_remote_code=True
)
model = AutoModelForCausalLM.from_pretrained(
    MODEL_PATH,
    torch_dtype=TORCH_TYPE,
    trust_remote_code=True,
).to(DEVICE).eval()

text_only_template = "A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions. USER: {} ASSISTANT:"

while True:
    image_path = input("image path >>>>> ")
    if image_path == '':
        print('You did not enter image path, the following will be a plain text conversation.')
        image = None
        text_only_first_query = True
    else:
        image = Image.open(image_path).convert('RGB')

    history = []

    while True:
        query = input("Human:")
        if query == "clear":
            break

        if image is None:
            if text_only_first_query:
                query = text_only_template.format(query)
                text_only_first_query = False
            else:
                old_prompt = ''
                for _, (old_query, response) in enumerate(history):
                    old_prompt += old_query + " " + response + "\n"
                query = old_prompt + "USER: {} ASSISTANT:".format(query)
        if image is None:
            input_by_model = model.build_conversation_input_ids(
                tokenizer,
                query=query,
                history=history,
                template_version='chat'
            )
        else:
            input_by_model = model.build_conversation_input_ids(
                tokenizer,
                query=query,
                history=history,
                images=[image],
                template_version='chat'
            )
        inputs = {
            'input_ids': input_by_model['input_ids'].unsqueeze(0).to(DEVICE),
            'token_type_ids': input_by_model['token_type_ids'].unsqueeze(0).to(DEVICE),
            'attention_mask': input_by_model['attention_mask'].unsqueeze(0).to(DEVICE),
            'images': [[input_by_model['images'][0].to(DEVICE).to(TORCH_TYPE)]] if image is not None else None,
        }
        gen_kwargs = {
            "max_new_tokens": 2048,
            "pad_token_id": 128002,  
        }
        with torch.no_grad():
            outputs = model.generate(**inputs, **gen_kwargs)
            outputs = outputs[:, inputs['input_ids'].shape[1]:]
            response = tokenizer.decode(outputs[0])
            response = response.split("<|end_of_text|>")[0]
            print("\nCogVLM2:", response)
        history.append((query, response))

许可证

本模型遵循 CogVLM2 许可协议发布。对于使用 Meta Llama 3 构建模型的情况,请亦遵守 LLAMA3 许可协议。

引用

如果您认为我们的工作对您有所帮助,请考虑引用以下论文

@misc{hong2024cogvlm2,
  title={CogVLM2: Visual Language Models for Image and Video Understanding},
  author={Hong, Wenyi and Wang, Weihan and Ding, Ming and Yu, Wenmeng and Lv, Qingsong and Wang, Yan and Cheng, Yean and Huang, Shiyu and Ji, Junhui and Xue, Zhao and others},
  year={2024}
  eprint={2408.16500},
  archivePrefix={arXiv},
  primaryClass={cs.CV}
}

@misc{wang2023cogvlm,
      title={CogVLM: Visual Expert for Pretrained Language Models}, 
      author={Weihan Wang and Qingsong Lv and Wenmeng Yu and Wenyi Hong and Ji Qi and Yan Wang and Junhui Ji and Zhuoyi Yang and Lei Zhao and Xixuan Song and Jiazheng Xu and Bin Xu and Juanzi Li and Yuxiao Dong and Ming Ding and Jie Tang},
      year={2023},
      eprint={2311.03079},
      archivePrefix={arXiv},
      primaryClass={cs.CV}
}
# 专业翻译服务

## 服务概述
我们提供高质量的文本翻译服务,旨在满足不同领域的专业需求。无论是法律文件、医学文献还是技术手册,我们的团队都能确保翻译的准确性和流畅性。

## 服务特点
- **通俗易懂**:我们致力于将复杂的术语转化为易于理解的语言,确保信息传达无障碍。
- **专业精准**:我们的翻译团队由行业专家组成,确保每一项翻译都符合专业标准。
- **优雅流畅**:我们注重语言的优美性和表达的流畅性,使翻译文本不仅准确,而且富有文采。

## 服务流程
1. **需求分析**:与客户沟通,了解翻译的具体需求和目标。
2. **文本评估**:对原文进行详细分析,确定翻译的难度和所需时间。
3. **翻译执行**:由专业翻译人员进行文本翻译,确保质量。
4. **校对审核**:经过多轮校对和审核,确保翻译的准确性和一致性。
5. **交付反馈**:将最终翻译文本交付给客户,并收集反馈以持续改进服务质量。

## 适用领域
- **法律**:合同、法规、诉讼文件等。
- **医学**:研究报告、临床试验、药品说明书等。
- **技术**:用户手册、技术规范、专利文件等。
- **商务**:市场调研、商业计划、营销材料等。

## 联系我们
如有任何翻译需求或疑问,请随时联系我们的客户服务团队。我们期待为您提供卓越的翻译服务。