TensorFlow, Google द्वारा प्रदान किया गया एक मशीन लर्निंग फ्रेमवर्क है। यह एक ओपन-सोर्स फ्रेमवर्क है जिसका उपयोग Python के साथ एल्गोरिदम, डीप लर्निंग एप्लिकेशन, और बहुत कुछ लागू करने के लिए किया जाता है। इसका उपयोग अनुसंधान और उत्पादन उद्देश्यों के लिए किया जाता है।
इंस्टॉलेशन
Windows पर 'tensorflow' पैकेज को निम्न कमांड से इंस्टॉल किया जा सकता है:
pip install tensorflow
टेंसर
टेंसर TensorFlow में उपयोग की जाने वाली एक डेटा संरचना है। यह फ्लो डायग्राम में एज को जोड़ने में मदद करता है। इस फ्लो डायग्राम को 'डेटा फ्लो ग्राफ' के रूप में जाना जाता है। टेंसर एक बहुआयामी सरणी या सूची के अलावा कुछ नहीं हैं।
Iliad डेटासेट
हम Iliad डेटासेट का उपयोग करेंगे, जिसमें विलियम कूपर, एडवर्ड (डर्बी के अर्ल), और सैमुअल बटलर के तीन अनुवाद कार्यों का टेक्स्ट डेटा होता है। मॉडल को एक पंक्ति टेक्स्ट दिए जाने पर अनुवादक की पहचान करने के लिए प्रशिक्षित किया जाता है। उपयोग की गई टेक्स्ट फाइलें पूर्व-प्रसंस्कृत हैं।
Google Colaboratory
हम नीचे दिए गए कोड को चलाने के लिए Google Colaboratory का उपयोग कर रहे हैं। Google Colab ब्राउज़र पर Python कोड चलाने में मदद करता है और GPUs तक मुफ्त पहुंच प्रदान करता है।
कोड उदाहरण
print("Prepare the dataset for training")
tokenizer = tf_text.UnicodeScriptTokenizer()
print("Defining a function named 'tokenize' to tokenize the text data")
def tokenize(text, unused_label):
lower_case = tf_text.case_fold_utf8(text)
return tokenizer.tokenize(lower_case)
tokenized_ds = all_labeled_data.map(tokenize)
print("Iterate over the dataset and print a few samples")
for text_batch in tokenized_ds.take(6):
print("Tokens: ", text_batch.numpy())
कोड क्रेडिट: https://www.tensorflow.org/tutorials/load_data/text
आउटपुट
Prepare the dataset for training Defining a function named 'tokenize' to tokenize the text data WARNING:tensorflow:From /usr/local/lib/python3.6/distpackages/tensorflow/python/util/dispatch.py:201: batch_gather (from tensorflow.python.ops.array_ops) is deprecated and will be removed after 2017-10-25. Instructions for updating: `tf.batch_gather` is deprecated, please use `tf.gather` with `batch_dims=-1` instead. Iterate over the dataset and print a few samples Tokens: [b'but' b'i' b'have' b'now' b'both' b'tasted' b'food' b',' b'and' b'given'] Tokens: [b'all' b'these' b'shall' b'now' b'be' b'thine' b':' b'but' b'if' b'the' b'gods'] Tokens: [b'their' b'spiry' b'summits' b'waved' b'.' b'there' b',' b'unperceived'] Tokens: [b'"' b'i' b'pray' b'you' b',' b'would' b'you' b'show' b'your' b'love' b',' b'dear' b'friends' b','] Tokens: [b'entering' b'beneath' b'the' b'clavicle' b'the' b'point'] Tokens: [b'but' b'grief' b',' b'his' b'father' b'lost' b',' b'awaits' b'him' b'now' b',']
व्याख्या
एक 'tokenize' फ़ंक्शन परिभाषित किया गया है जो डेटासेट में वाक्यों को स्पेस हटाकर शब्दों में विभाजित करता है।
यह फ़ंक्शन पूरे डेटासेट पर कॉल किया जाता है।
टोकनाइज़ करने के बाद डेटासेट का एक नमूना कंसोल पर प्रदर्शित होता है।