Home › Forums › Fórum Processamento de Linguagem Natural com BERT e Python › Percorrer uma lista com o get_prediction
Tagged: Avaliação do modelo
- This topic has 4 replies, 3 voices, and was last updated 11 months, 2 weeks ago by
Jones Granatyr.
Viewing 5 posts - 1 through 5 (of 5 total)
- AuthorPosts
- 13 de April de 2022 at 12:58 #34227
Boa tardde, nesta aula aprendemos como submeter uma frase ao treinamento
Gostaria de saber como faço para submeter uma lista com varias frases, para não precisar analisar de uma em uma e printar o resultado ao lado, na forma de uma nova coluna com 0 e 1 (negativo e positivo).
13 de April de 2022 at 12:59 #34228Como faria isso?
13 de April de 2022 at 18:12 #34229Olá Micael,
Você pode primeiro fazer uma pequena modificação na função
get_predictions
, para retornar o valor ao invés de exibi-lo na tela:def get_prediction(sentence): tokens = encode_sentence(sentence) inputs = tf.expand_dims(tokens, 0) # (batch_size) (1,...) output = Dcnn(inputs, training=False) sentiment = math.floor(output*2) if sentiment == 0: return 'negative' elif sentiment == 1: return 'positive'
Agora, pode organizar suas frases em um dataframe e adicionar o resultado desta forma:
texts = ["This movie was pretty interesting", "I'd rather not do that again", "What a great time to be alive", "I wish this never happened"] df = pd.DataFrame({'text': texts}) df['emotion'] = df['text'].map(get_prediction) print(df) <out> text emotion -------------------------------------------- 0 This movie was pretty interesting positive 1 I'd rather not do that again negative 2 What a great time to be alive positive 3 I wish this never happened negative
- This reply was modified 3 years ago by
Denny Ceccon.
13 de April de 2022 at 21:22 #34232Boa noite!
Funcionol perfeitamente! Muito obrigado!
9 de May de 2024 at 09:50 #44753Qualquer outra dúvida é só avisar!
- This reply was modified 3 years ago by
- AuthorPosts
Viewing 5 posts - 1 through 5 (of 5 total)
- You must be logged in to reply to this topic.