Trying to create language translator

gives error ---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
in
1 # Convert src_sequences and tgt_sequences to tensors
2 src_sequences = tf.convert_to_tensor(src_sequences)
----> 3 tgt_sequences = tf.convert_to_tensor(tgt_sequences)
4
5 # Create a dataset object for the preprocessed data

1 frames
/usr/local/lib/python3.8/dist-packages/tensorflow/python/framework/constant_op.py in convert_to_eager_tensor(value, ctx, dtype)
100 dtype = dtypes.as_dtype(dtype).as_datatype_enum
101 ctx.ensure_initialized()
→ 102 return ops.EagerTensor(value, ctx.device_name code

import tensorflow as tf from tensorflow.python.keras.layers import Embedding, LSTM, Dense, Attention from tensorflow.python.keras.models import Sequential src_texts = ['this is a test', 'how are you today'] tgt_texts = ['ceci est un test', 'comment vas-tu aujourd hui'] src_tokenizer = tf.keras.preprocessing.text.Tokenizer() src_tokenizer.fit_on_texts(src_texts) src_sequences = src_tokenizer.texts_to_sequences(src_texts) tgt_tokenizer = tf.keras.preprocessing.text.Tokenizer() tgt_tokenizer.fit_on_texts(tgt_texts) tgt_sequences = tgt_tokenizer.texts_to_sequences(tgt_texts)

src_vocab_size = len(src_tokenizer.word_index) + 1 tgt_vocab_size = len(tgt_tokenizer.word_index) + 1

src_sequences = tf.convert_to_tensor(src_sequences)
tgt_sequences = tf.convert_to_tensor(tgt_sequences)
dataset = tf.data.Dataset.from_tensor_slices((src_sequences, tgt_sequences)).batch(1)

the error retuerned from here.
what’s wrong? please help me…

i’m beginner for this and 14years old.

sorry for bad english… :grin:

We will be building a simple application in which we will be showing an EditText field and we will add any input to that TextField. Along with that, we will be displaying a Button to translate that text to the German language. After clicking that button our text will be translated to the German language which we can get to see in the text view. A sample video is given below to get an idea about what we are going to do in this article. Note that we are going to implement this project using the Java language.

1 Like

@zaanind,

Welcome to the Tensorflow Forum!

This problem appears because the lists in tgt_sequences are not equal. Here you can use tf.ragged.constant to convert to a ragged tensor.

Please refer to the working code here.

We have tutorials on Neural machine translation using Transformer and attention may help you for language translation.

Thank you!

1 Like

i can help you to train it with sinhala language if you like.
:grin: but i don’t know java!