如何使用Python和Tensorflow探索Stack Overflow問題資料集並檢視樣本檔案?


Tensorflow是谷歌提供的機器學習框架。它是一個開源框架,與Python結合使用,可以實現演算法、深度學習應用程式等等。它用於研究和生產目的。

可以使用以下程式碼行在Windows上安裝“tensorflow”包:

pip install tensorflow

Keras是ONEIROS(開放式神經電子智慧機器人作業系統)專案研究的一部分。Keras是一個用Python編寫的深度學習API。它是一個高階API,具有高效的介面,有助於解決機器學習問題。它執行在Tensorflow框架之上。它旨在幫助快速進行實驗。它提供了開發和封裝機器學習解決方案所需的必要抽象和構建塊。

Keras已經存在於Tensorflow包中。可以使用以下程式碼行訪問它。

import tensorflow
from tensorflow import keras

我們使用Google Colaboratory執行以下程式碼。Google Colab或Colaboratory有助於在瀏覽器上執行Python程式碼,無需任何配置,並可免費訪問GPU(圖形處理單元)。Colaboratory構建在Jupyter Notebook之上。以下是程式碼片段:

示例

print("The files in the directory are listed out")
list(dataset_dir.iterdir())
print("The stackoverflow questions are present in the 'train/' directory")
train_dir = dataset_dir/'train'
list(train_dir.iterdir())
sample_file = train_dir/'python/1755.txt'
print("A sample file is displayed")
with open(sample_file) as f:
   print(f.read())

程式碼來源:https://www.tensorflow.org/tutorials/load_data/text

輸出

The files in the directory are listed out
The stackoverflow questions are present in the 'train/' directory
A sample file is displayed
why does this blank program print true x=true.def stupid():. x=false.stupid().print x

解釋

  • 列出了目錄中的檔案。

  • Stack Overflow資料集中文字資料的樣本顯示在控制檯上。

更新於:2021年1月18日

107 次瀏覽

啟動您的職業生涯

透過完成課程獲得認證

開始學習
廣告
© . All rights reserved.