- Hands-On Neural Networks with Keras
- Niloy Purkait
- 377字
- 2021-06-24 15:45:14
Accessing model predictions
In the MNIST example, we used the Softmax activation function as our last layer. You may recall that the layer generated an array of 10 probability scores, adding up to 1 for a given input. Each of those 10 scores referred to the likelihood of the image being presented to our network corresponding to one of the output classes (that is, it is 90% sure it sees a 1, and 10% sure it sees a 7, for example). This approach made sense for a classification task with 10 categories. In our sentiment analysis problem, we chose a sigmoid activation function, because we are dealing with binary categories. Using the sigmoid here simply forces our network to output a prediction between 0 and 1 for any given instance of data. Hence, a value closer to 1 means that our network believes that the given piece of information is more likely to be a positive review, whereas a value closer to zero states our network's conviction of having found a negative review. To view our model's predictions, we simply define a variable called predictions by using the predict() parameter on our trained model and passing it our test set. Now we can check our network predictions on a given example from this set, as follows:
predictions=model.predict([x_test])
predictions[5]
In this case, it appears that our network is quite confident that review 5 from our test set is a positive review. Not only can we check whether this is indeed the case by checking the label stored in y_test[5], we can also decode the review itself due to the decoder function we built earlier. Let's put our network's prediction to the test by decoding review 5 and checking its label:
y_test[5], decode_review(5, split='test')
It turns out our network is right. This is an example of a complex linguistic pattern that requires a higher-level understanding of linguistic syntax, real-world entities, relational logic, and the propensity for humans to blabber aimlessly. Yet, with only 12 neurons, our network has seemingly understood the underlying sentiment that's encoded in this piece of information. It makes a prediction with a high degree of certainty (99.99%), despite the presence of words such as disgusting, which are very likely to appear in negative reviews.
- PPT,要你好看
- Go Machine Learning Projects
- 基于LabWindows/CVI的虚拟仪器设计与应用
- Mobile DevOps
- Mastering Salesforce CRM Administration
- Visual C# 2008开发技术详解
- 统计策略搜索强化学习方法及应用
- CompTIA Network+ Certification Guide
- RPA(机器人流程自动化)快速入门:基于Blue Prism
- INSTANT Autodesk Revit 2013 Customization with .NET How-to
- Prometheus监控实战
- 菜鸟起飞系统安装与重装
- Excel 2007常见技法与行业应用实例精讲
- INSTANT Heat Maps in R:How-to
- Silverlight 2完美征程