Community RSS Feed
https://community.wolfram.com
RSS Feed for Wolfram Community showing any discussions in tag Machine Learning sorted by activeVisualizing Text Sentiments in RGBColor and ChromaticityPlot
https://community.wolfram.com/groups/-/m/t/1552094
Today, I got an idea, Why not show text sentiments value from different author in just one-shot all together?
So I write a few lines of code in Mathematica 11.3, see attached Notebook.
The idea is very nature. As people said, every color represents an emotion, and vice versa.
So I use "warm" red to represent positive, "cool" blue for negative, and green for neutral.
Let's start an example from Alice.
sentence = TextSentences[ExampleData[{"Text", "AliceInWonderland"}]];
sentiment = Classify["Sentiment", #, "Probabilities"] & /@ sentence;
width = Floor[N[Sqrt[Length@sentiment]], 1];
plot = ArrayPlot[
Partition[Take[RGBColor @@@ sentiment, width^2], width],
ImageSize -> 300, PlotLabel -> "Alice in Wonderland"]
![enter image description here][1]
Then I got all texts plot in various color.
![enter image description here][2]
Result Discussion:**
----------------------
1. Typical "Neutral" sentiments: "Origin of Species","Declaration of Independence"
![enter image description here][3]
![enter image description here][4]
2. Typical "Positive + Negative" (maybe more dramatic) sentiments: Shakespeares "Hamlet"
,"Sonnets"
![enter image description here][5]
![enter image description here][6]
3. Non-English Text: Sentiments classify may not be very accurate.
![enter image description here][7]
![enter image description here][8]
Take a glance, if the text-color match the color in your mind?
====================================================
[1]: https://community.wolfram.com//c/portal/getImageAttachment?filename=example1.png&userId=569571
[2]: https://community.wolfram.com//c/portal/getImageAttachment?filename=All.png&userId=569571
[3]: https://community.wolfram.com//c/portal/getImageAttachment?filename=TextOriginOfSpecies.png&userId=569571
[4]: https://community.wolfram.com//c/portal/getImageAttachment?filename=TextDeclarationOfIndependence.png&userId=569571
[5]: https://community.wolfram.com//c/portal/getImageAttachment?filename=TextHamlet.png&userId=569571
[6]: https://community.wolfram.com//c/portal/getImageAttachment?filename=TextShakespearesSonnets.png&userId=569571
[7]: https://community.wolfram.com//c/portal/getImageAttachment?filename=TextFaustI.png&userId=569571
[8]: https://community.wolfram.com//c/portal/getImageAttachment?filename=TextDonQuixoteISpanish.png&userId=569571Frederick Wu2018-11-16T09:51:40ZGet right list of tensors data to port "Input" in NetTrain?
https://community.wolfram.com/groups/-/m/t/1549196
Dear all, my input and target data is prepared in tensor, which is filled from a file. Dimensions[input] yields {398,6,24,24}. First index is the training set number, second is channels (6) and 24 x 24 is my "image" size. In the same way I have prepared the target data, which is in a {398,6} tensor.
When I try to invoke NetTrain, it complains:
NetTrain[Net,{"Inputs"->input,"Targets"->target},{MaxTrainingRounds->1}]
> NetTrain: Data provided to port "Input" should be a list of 6×24×243-tensors.
**Obviously my understanding of tensors and lists seems to be flawed, why is {398,6,24,24} not a list of {6,24,24} tensors?**
The network is defined as follows, just two fully connected layers.
linear1 = LinearLayer[{6,24,24}, "Input"->{6,24,24}];
linear1 = NetInitialize[linear1];
linear2 = LinearLayer[{6}, "Input"->{6,24,24}];
linear2 = NetInitialize[linear2];
Net = NetChain[{linear1, linear2}];Markus Lenzing2018-11-13T12:57:04Z[WSS18] Introducing Hadamard Binary Neural Networks
https://community.wolfram.com/groups/-/m/t/1374288
##Introducing Hadamard Binary Neural Networks
Deep neural networks are an important tool in modern applications. It has become a major challenge to accelerate their training. As the complexity of our training tasks increase, the computation does too. For sustainable machine learning at scale, we need distributed systems that can leverage the available hardware effectively. This research hopes to exceed the current state of the art performance of neural networks by introducing a new architecture optimized for distributability. The scope of this work is not just limited to optimizing neural network training for large servers, but also to bring training to heterogeneous environments; paving way for a distributed peer to peer mesh computing platform that can harness the wasted resources of idle computers in a workplace for AI.
#### Network Architecture and Layer Evaluator
Here, I will describe the network and the Layer Evaluator, to get an in depth understanding of the network architecture.
Note:
- **hbActForward** : Forward binarization of Activations.
- **hbWForward** : Forward binarization of Weights.
- **binAggression** : Aggressiveness of binarization (Vector length to binarize)
Set up the Layer Evaluator.
layerEval[x_, layer_Association] := layerEval[x, Lookup[layer, "LayerType"], Lookup[layer, "Parameters"]];
layerEval[x_, "Sigmoid", param_] := 1/(1 + Exp[-x]);
layerEval[x_, "Ramp", param_] := Abs[x]*UnitStep[x];
layerEval[ x_, "LinearLayer", param_] := Dot[x, param["Weights"]];
layerEval[ x_, "BinLayer", param_] := Dot[hbActForward[x, binAggression], hbWForward[param["Weights"], binAggression]];
layerEval[x_, "BinarizeLayer", param_] := hbActForward[x, binAggression];
netEvaluate[net_, x_, "Training"] := FoldList[layerEval, x, net];
netEvaluate[net_, x_, "Test"] := Fold[layerEval, x, net];
Define the network
net = {<|"LayerType" -> "LinearLayer", "Parameters" -> <|"Weights" -> w0|>|>,
<|"LayerType" -> "Ramp"|>,
<|"LayerType" -> "BinarizeLayer"|>,
<|"LayerType" -> "BinLayer", "Parameters" -> <|"Weights" -> w1|>|>,
<|"LayerType" -> "Ramp"|>,
<|"LayerType" -> "BinLayer", "Parameters" -> <|"Weights" -> w2|>|>,
<|"LayerType" -> "Sigmoid"|> };
MatrixForm@netEvaluate[net, input[[1 ;; 3]], "Test" ] (* Giving network inputs *)
![enter image description here][1]
#### Advantages of Hadamard Binarization
- Faster convergence with respect to vanilla binarization techniques.
- Consistently about 10 times faster than CMMA algorithm.
- Angle of randomly initialized vectors preserved in high dimensional spaces. (Approximately 37 degrees as vector length approach infinity.)
- Reduced communication times for distributed deep learning.
- Optimization of im2col algorithm for faster inference.
- Reduction of model sizes.
### Accuracy analysis
![enter image description here][2]
As seen above, the HBNN model gives 87% accuracy, whereas the BNN model (Binary Neural Networks) give only 82%. These networks have only been trained for 5 epochs.
### Performance Analysis
X Axis: Matrix Size
| Y Axis: Time (seconds)
**CMMA vs xHBNN**
![enter image description here][3]
**MKL vs xHBNN**
$\hspace{1mm}$![enter image description here][4]
### Visualize weight histograms
![enter image description here][5]
It is evident that the Hadamard BNN preserves the distribution of the weights much better. Note that the BNN graph has a logarithmic vertical axis, for representation purposes.
### Demonstration of the angle preservation ability of the HBNN architecture
![enter image description here][6]
Binarization approximately preserves the direction of high dimensional vectors. The figure above demonstrates that the angle between a random vector (from a standard normal distribution) and its binarized version converges to ~ 37 degrees as the dimension of the vector goes to infinity. This angle is exceedingly small in high dimensions.
[1]: http://community.wolfram.com//c/portal/getImageAttachment?filename=tempz.png&userId=1302993
[2]: http://community.wolfram.com//c/portal/getImageAttachment?filename=accuracy.png&userId=1302993
[3]: http://community.wolfram.com//c/portal/getImageAttachment?filename=6613xCma.png&userId=1302993
[4]: http://community.wolfram.com//c/portal/getImageAttachment?filename=xMKL.png&userId=1302993
[5]: http://community.wolfram.com//c/portal/getImageAttachment?filename=histogram.png&userId=1302993
[6]: http://community.wolfram.com//c/portal/getImageAttachment?filename=anglepreserve.png&userId=1302993Yash Akhauri2018-07-10T22:12:26Z