小编Nid*_*utt的帖子

AttributeError:“列表”对象没有属性“大小”Hugging-Face 转换器

我正在尝试使用 Huggingface 将内容从英语转换为印地语。这是代码片段

from transformers import AutoTokenizer, AutoModelForSeq2SeqLM

tokenizer = AutoTokenizer.from_pretrained("Helsinki-NLP/opus-mt-en-hi")

model = AutoModelForSeq2SeqLM.from_pretrained("Helsinki-NLP/opus-mt-en-hi")
text = "Hello my friends! How are you doing today?"
tokenized_text = tokenizer.prepare_seq2seq_batch([text])

# Perform translation and decode the output
translation = model.generate(**tokenized_text)
translated_text = tokenizer.batch_decode(translation, skip_special_tokens=True)[0]

# Print translated text
print(translated_text)
Run Code Online (Sandbox Code Playgroud)

我在尝试调用“模型”上生成的方法时收到此错误。

属性错误:“列表”对象没有属性“大小”。

我正在 Transformer 版本 4.3.3 上运行。

nlp python-3.x huggingface-transformers

6
推荐指数
1
解决办法
1万
查看次数

Python 生成到不同的 Kafka 分区

我正在尝试通过经典的 Twitter 流媒体示例来学习 Kafka。我正在尝试使用我的生产者将基于 2 个过滤器的 Twitter 数据流式传输到同一主题的不同分区。例如,Twitter 数据的一个分区的 track='Google' 和另一分区的 track='Apple'。

class Producer(StreamListener):
    def __init__(self, producer):
        self.producer = producer

    def on_data(self, data):
        self.producer.send(topic_name, value=data)
        return True

    def on_error(self, error):
        print(error)


twitter_stream = Stream(auth, Producer(producer))
twitter_stream.filter(track=["Google"])
Run Code Online (Sandbox Code Playgroud)

如何添加另一个轨道并将该数据流式传输到另一个分区。

同样,我如何让我的消费者从特定分区消费。

consumer = KafkaConsumer(
    topic_name,
     bootstrap_servers=['localhost:9092'],
     auto_offset_reset='latest',
     enable_auto_commit=True,
     auto_commit_interval_ms =  5000,
     max_poll_records = 100,
     value_deserializer=lambda x: json.loads(x.decode('utf-8')))
Run Code Online (Sandbox Code Playgroud)

python apache-kafka twitter-streaming-api

4
推荐指数
1
解决办法
5909
查看次数