TensorFlow, Google द्वारा प्रदान किया गया एक मशीन लर्निंग फ्रेमवर्क है। यह एक ओपन-सोर्स फ्रेमवर्क है जिसका उपयोग Python के साथ एल्गोरिदम, डीप लर्निंग एप्लिकेशन, और बहुत कुछ लागू करने के लिए किया जाता है। इसका उपयोग अनुसंधान और उत्पादन उद्देश्यों के लिए किया जाता है।
इंस्टॉलेशन
Windows पर 'tensorflow' पैकेज को निम्न कमांड से इंस्टॉल किया जा सकता है:
pip install tensorflow
टेंसर और उसके गुण
टेंसर TensorFlow में उपयोग की जाने वाली एक डेटा संरचना है। यह फ्लो डायग्राम में एज को जोड़ने में मदद करता है। इस फ्लो डायग्राम को 'डेटा फ्लो ग्राफ' के रूप में जाना जाता है। टेंसर एक बहुआयामी सरणी या सूची के अलावा कुछ नहीं हैं।
इन्हें तीन मुख्य विशेषताओं का उपयोग करके पहचाना जा सकता है:
रैंक (Rank) - यह टेंसर की आयामिकता के बारे में बताता है।
टाइप (Type) - यह टेंसर के तत्वों से जुड़े डेटा टाइप के बारे में बताता है।
शेप (Shape) - यह पंक्तियों और स्तंभों की संख्या को एक साथ दर्शाता है।
Iliad डेटासेट
हम Iliad डेटासेट का उपयोग करेंगे, जिसमें विलियम कूपर, एडवर्ड (डर्बी के अर्ल) और सैमुअल बटलर के तीन अनुवाद कार्यों का टेक्स्ट डेटा होता है। मॉडल को एक पंक्ति टेक्स्ट दिए जाने पर अनुवादक की पहचान करने के लिए प्रशिक्षित किया जाता है। उपयोग की गई टेक्स्ट फाइलें पूर्व-प्रसंस्कृत हैं।
Google Colaboratory
हम नीचे दिए गए कोड को चलाने के लिए Google Colaboratory का उपयोग कर रहे हैं। Google Colab ब्राउज़र पर Python कोड चलाने में मदद करता है और GPUs तक मुफ्त पहुंच प्रदान करता है।
कोड उदाहरण
print("Loading the Illiad dataset")
DIRECTORY_URL = 'https://storage.googleapis.com/download.tensorflow.org/data/illiad/'
FILE_NAMES = ['cowper.txt', 'derby.txt', 'butler.txt']
print("Iterating through the name of the files")
for name in FILE_NAMES:
text_dir = utils.get_file(name, origin=DIRECTORY_URL + name)
parent_dir = pathlib.Path(text_dir).parent
print("The list of files in the directory")
print(list(parent_dir.iterdir()))
कोड क्रेडिट: https://www.tensorflow.org/tutorials/load_data/text
आउटपुट
Loading the Illiad dataset
Iterating through the name of the files
Downloading data from https://storage.googleapis.com/download.tensorflow.org/data/illiad/cowper.txt
819200/815980 [==============================] - 0s 0us/step
Downloading data from https://storage.googleapis.com/download.tensorflow.org/data/illiad/derby.txt
811008/809730 [==============================] - 0s 0us/step
Downloading data from https://storage.googleapis.com/download.tensorflow.org/data/illiad/butler.txt
811008/807992 [==============================] - 0s 0us/step
The list of files in the directory
[PosixPath('/root/.keras/datasets/derby.txt'), PosixPath('/root/.keras/datasets/cowper.txt'), PosixPath('/root/.keras/datasets/butler.txt')]
[]
व्याख्या
'tf.data.TextLineDataset' का उपयोग टेक्स्ट फाइलों से उदाहरण लोड करने के लिए किया जाता है।
'tf.text' का उपयोग डेटा को पूर्व-प्रसंस्कृत करने के लिए किया जाता है।
सबसे पहले, डेटासेट को डाउनलोड और एक्सप्लोर किया जाता है।