একই দৈর্ঘ্যের একাধিক স্ট্রিং tf.Tensor ইনপুট ভ্যালু হিসেবে ব্যবহার করে এনকোড করা যায়। যখন ভিন্ন দৈর্ঘ্যের একাধিক স্ট্রিং এনকোড করা দরকার, তবে tf.RaggedTensor ইনপুট হিসেবে ব্যবহার করা উচিত। যদি একটি টেনসরে প্যাডেড/স্পার্স ফরম্যাটে একাধিক স্ট্রিং থাকে, তবে এটি tf.RaggedTensor-এ কনভার্ট করে unicode_encode মেথড কল করতে হয়।
আরও পড়ুন: টেনসরফ্লো কী এবং কেরাস কীভাবে টেনসরফ্লোর সাথে কাজ করে নিউরাল নেটওয়ার্ক তৈরি করতে?
আমরা বুঝব কিভাবে পাইথনে ইউনিকোড স্ট্রিং রিপ্রেজেন্ট করতে হয় এবং ইউনিকোড সমতুল্য ব্যবহার করে সেগুলো ম্যানিপুলেট করতে হয়। প্রথমে, আমরা ইউনিকোড স্ট্রিংগুলোর টোকেনে আলাদা করব স্ক্রিপ্ট ডিটেকশনের সাহায্যে স্ট্যান্ডার্ড স্ট্রিং অপারেশনগুলির ইউনিকোড সমতুল্য ব্যবহার করে।
নিচের কোড চালাতে আমরা Google Colaboratory ব্যবহার করছি। Google Colab বা Colaboratory ব্রাউজারে পাইথন কোড চালাতে সাহায্য করে এবং শূন্য কনফিগারেশনের সাথে ফ্রি GPU (গ্রাফিক্যাল প্রসেসিং ইউনিট) অ্যাক্সেস দেয়। Colaboratory Jupyter Notebook-এর উপরে তৈরি।
print("When encoding multiple strings of same lengths, tf.Tensor is used as input")
tf.strings.unicode_encode([[99, 97, 116], [100, 111, 103], [99, 111, 119]], output_encoding='UTF-8')
print("When encoding multiple strings with varying length, a tf.RaggedTensor should be used as input:")
tf.strings.unicode_encode(batch_chars_ragged, output_encoding='UTF-8')
print("If there is a tensor with multiple strings in padded/sparse format, convert it to a tf.RaggedTensor before calling unicode_encode")
tf.strings.unicode_encode(
tf.RaggedTensor.from_sparse(batch_chars_sparse),
output_encoding='UTF-8')
tf.strings.unicode_encode(
tf.RaggedTensor.from_tensor(batch_chars_padded, padding=-1),
output_encoding='UTF-8')
কোড ক্রেডিট: https://www.tensorflow.org/tutorials/load_data/unicode
আউটপুট
When encoding multiple strings of same lengths, tf.Tensor is used as input When encoding multiple strings with varying length, a tf.RaggedTensor should be used as input: If there is a tensor with multiple strings in padded/sparse format, convert it to a tf.RaggedTensor before calling unicode_encode
ব্যাখ্যা
- একই দৈর্ঘ্যের একাধিক স্ট্রিং এনকোড করার সময়
tf.Tensorইনপুট হিসেবে ব্যবহার করা যায়। - ভিন্ন দৈর্ঘ্যের একাধিক স্ট্রিং এনকোড করার সময়
tf.RaggedTensorইনপুট হিসেবে ব্যবহার করা যায়। - যদি প্যাডেড/স্পার্স ফরম্যাটে একাধিক স্ট্রিংയুক্ত টেনসর থাকে, তবে
unicode_encodeকল করার আগে এটিtf.RaggedTensor-এ কনভার্ট করতে হয়।