Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

366
Visualizações
¿Cómo convertir la secuencia predicha de nuevo en texto en keras?

Tengo un modelo de aprendizaje de secuencia a secuencia que funciona bien y es capaz de predecir algunos resultados. El problema es que no tengo idea de cómo volver a convertir la salida a la secuencia de texto.

Este es mi código.

 from keras.preprocessing.text import Tokenizer,base_filter from keras.preprocessing.sequence import pad_sequences from keras.models import Sequential from keras.layers import Dense txt1="""What makes this problem difficult is that the sequences can vary in length, be comprised of a very large vocabulary of input symbols and may require the model to learn the long term context or dependencies between symbols in the input sequence.""" #txt1 is used for fitting tk = Tokenizer(nb_words=2000, filters=base_filter(), lower=True, split=" ") tk.fit_on_texts(txt1) #convert text to sequence t= tk.texts_to_sequences(txt1) #padding to feed the sequence to keras model t=pad_sequences(t, maxlen=10) model = Sequential() model.add(Dense(10,input_dim=10)) model.add(Dense(10,activation='softmax')) model.compile(loss='categorical_crossentropy', optimizer='adam',metrics=['accuracy']) #predicting new sequcenc pred=model.predict(t) #Convert predicted sequence to text pred=??
over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

Puede usar directamente la función inversa tokenizer.sequences_to_texts .

 text = tokenizer.sequences_to_texts(<list-of-integer-equivalent-encodings>)

He probado lo anterior y funciona como se esperaba.

PD.: Tenga mucho cuidado de que el argumento sea la lista de codificaciones enteras y no las One Hot.

over 4 years ago · Santiago Trujillo Relatório

0

Aquí hay una solución que encontré:

 reverse_word_map = dict(map(reversed, tokenizer.word_index.items()))
over 4 years ago · Santiago Trujillo Relatório

0

Tuve que resolver el mismo problema, así que así es como terminé haciéndolo (inspirado en el diccionario invertido de @Ben Useman).

 # Importing library from keras.preprocessing.text import Tokenizer # My texts texts = ['These are two crazy sentences', 'that I want to convert back and forth'] # Creating a tokenizer tokenizer = Tokenizer(lower=True) # Building word indices tokenizer.fit_on_texts(texts) # Tokenizing sentences sentences = tokenizer.texts_to_sequences(texts) >sentences >[[1, 2, 3, 4, 5], [6, 7, 8, 9, 10, 11, 12, 13]] # Creating a reverse dictionary reverse_word_map = dict(map(reversed, tokenizer.word_index.items())) # Function takes a tokenized sentence and returns the words def sequence_to_text(list_of_indices): # Looking up words in dictionary words = [reverse_word_map.get(letter) for letter in list_of_indices] return(words) # Creating texts my_texts = list(map(sequence_to_text, sentences)) >my_texts >[['these', 'are', 'two', 'crazy', 'sentences'], ['that', 'i', 'want', 'to', 'convert', 'back', 'and', 'forth']]
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda