【发布时间】:2023-01-28 06:06:51
【问题描述】:
我正在尝试在 R 中使用不同的 Huggingface 模型。 这通过 reticulate 导入 transformers 包来工作(谢谢,https://rpubs.com/eR_ic/transfoRmers)
输入只需要一个字符串的模型对我有用。 有些模型需要一个列表或一个向量,我根本不知道从哪里获得有关如何准确调用模型的信息。
以这个模型为例。 https://huggingface.co/openai/clip-vit-base-patch32。
从 python 示例中我知道它需要一张照片和(我假设)可能类的字符向量。
Python 输入是:text=["a photo of a cat", "a photo of a dog"], images=image
library(reticulate)
library(here)
library(tidyverse)
transformers <- reticulate::import("transformers")
image_classification_zero_shot <- transformers$pipeline(task = "zero-shot-image-classification", model = "openai/clip-vit-base-patch32")
image_classification <- transformers$pipeline(task = "image-classification", model = "microsoft/beit-base-patch16-224-pt22k-ft22k")
image_url <- "http://images.cocodataset.org/val2017/000000039769.jpg"
只需要图像的模型就可以工作
image_classification(images = image_url)
还需要使用类输入字符的模型不起作用。
image_classification_zero_shot(text = c("cats", "dogs"), images = image_url)
image_classification_zero_shot(text = "[cats, dogs]", images = image_url)
> Error in py_call_impl(callable, dots$args, dots$keywords) :
TypeError: object of type 'NoneType' has no len()
View(image_classification_zero_shot) 不产生任何信息。
- 如何让零射击模型工作?
- 我通常如何获取有关如何在 R 中调用这些模型的信息?这是一个函数,难道我不能在某处(在 R 中或在 huggingface 中)找到有关其参数的信息吗?
非常感谢你!
【问题讨论】:
标签: r huggingface-transformers reticulate