- This topic has 4 replies, 3 voices, and was last updated 2 years, 1 month ago by .
Viewing 5 posts - 1 through 5 (of 5 total)
Viewing 5 posts - 1 through 5 (of 5 total)
- You must be logged in to reply to this topic.
Home › Forums › Fórum Processamento de Linguagem Natural com BERT e Python › Percorrer uma lista com o get_prediction
Tagged: Avaliação do modelo
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).
Como faria isso?
Olá 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
Boa noite!
Funcionol perfeitamente! Muito obrigado!
Qualquer outra dúvida é só avisar!