Sentence vectors for fasttext - fasttext

I tried for creating sentence vectors in fasttext for a single line in english in python, but all i got was solution related to CLI in fasttext.
Link for fast test sentence vector creation
I want a function or a library that can easily provide me sentence vector for the input sentence in an english text form that I can use it in my python script.

This one:
https://pypi.org/project/fasttext/
Then we just need to average or sum output vectors for each token in a sentence.

Related

Is there a way to stack multiple 2x2 matrices in MATLAB into a multidimensional array in a simpler way (e.g. without using "cat" or "reshape")?

I am receiving a text file with 1000 matrices of size 2x2 each day from someone, in the following format (only 3 matrices are shown here instead of 1000):
0.96875000 0.03125000
0.03125000 0.96875000
0.96875000 0.01562500
0.03125000 0.98437500
0.99218800 0.03125000
0.00781250 0.96875000
I need to make a 2x2x1000 array in MATLAB. Ideally I could do something simple like:
[0.96875000 0.03125000
0.03125000 0.96875000;
0.96875000 0.01562500
0.03125000 0.98437500;
0.99218800 0.03125000
0.00781250 0.96875000]
After reading the MATLAB documentation on multidimensional arrays and the MATLAB documentation for the cat function, I figured out that I could make the required array in the following way (the first argument of cat is 3 because I'm concatenating the 2x2 matrices along the 3rd dimension):
cat(3,...
[0.96875000 0.03125000
0.03125000 0.96875000],...
[0.96875000 0.01562500
0.03125000 0.98437500],...
[0.99218800 0.03125000
0.00781250 0.96875000])
But that does not work if I put spacing between the lines as in my "ideal" example above, and the need for all the commas and dots makes it a bit uglier in my opinion.
While writing this question, I have discovered that I can run my "ideal" example and then use reshape, which I prefer over my solution using the cat function. For this, I don't even need the semi-colons. However Cris Luengo correctly pointed out in the comments that reshape is not enough and permute is also needed, and then Luis Mendo pointed out in chat that the solution is not so simple:
permute(reshape(ideal.',2,2,[]),[2 1 3])
Andras Deak has done what we thought was impossible, which is to remove the transpose, but the solution is still quite complicated, and was not easy to engineer:
permute(reshape(ideal,2,[],2),[1 3 2])
Ideally one would not need to use cat or reshape to make a 3D array, when the original data is already so nicely formatted in what the human eye can already see is a 3D array of several 2x2 matrices.
Is there a simpler way to build the 3D array in MATLAB using the data in the format I have?
So far I have done the following on my own:
Searched online and found the above two MATLAB documentation articles which lead me to the above solution using cat
Came up with the above solution using reshape while writing this question, then it got improved by Cris and Luis in the comments and chat 😊.
Also: I tried saving the data in a .txt file and clicked import in MATLAB, knowing that the import GUI gives some options for how the data is to be organized in the resulting MATLAB array, but there did not seem to be any option to make this a 3D array.
Indeed there is no "direct" way to import this text as a 3D matrix. This is the easiest way I can come up with:
Save the input as a .txt file
Use the import tool (Import Data button in the Variable toolbar) to import the data as a Mx2 matrix. Choose "Numeric Matrix" as "Output Type". And you can "exclude rows with" "blank cells" to avoid the empty rows.
Besides reshape() and permute(), using cell array to format it as below might be more intuitive and less error prone to someones.
% The number of 2x2 matrices
N = size(m,1)/2;
% Split each 2x2 matrix into a cell
c = mat2cell(m, 2*ones(1,N), 1);
% Concatenate along the 3rd dimension
output3DMatrix = cat(3, c{:});

How to create a Matlab symbol composition ∆t?

I'd like to create a single symbol which is contains a delta "∆" and a t.
For visualisation purposes i use Matlab Live Script.
Combining several latin letters is easy done by:
sym('dt')
But these either result in an exception or don't do a conversion:
sym('Delta t')
sym('Deltat')
The workaround to multiply two symbols does not work in all cases:
sym('Delta')*sym('t')
(sym('Delta')*sym('t'))^2
However, if i square the symbol, i'd like to have this behavior:
sym('dt')^2
But it should contain the delta symbol:
Is this what you want?
title('\Deltat')
If you want, you can also do
title('\Deltat^{2}')
The answer is no, you cant use non-ASCII for variables in MATLAB. This means no \Delta, no \epsilon, or any other non-standard chars.
You can generate the LaTeX representation of the results, and then print them either in text in MATLAB or in your favourite LaTeX editor with the function latex

How can I read a text file which has a strings n the first row and numbers and symbols in the next rows on octave?

I have a text file which contains titles for each column on the first row, and then numbers and symbols (such as "pi" for pi=3.14 or a distance represented with "d" or angle represented with "beta") And I
The text file is as follows:
Example of text file to be read
It works perfectly in MATLAB using readtable('text.txt') and I obtain the following:
Result in MATLAB
But, I am not able to get the same result in Octave. Is there a function in Octave that allows me to extract all the information from the text file similarly to MATLAB?
Thank you
you can read such file using textread in octave, see
https://octave.sourceforge.io/octave/function/textread.html

How to find missing value from equation using java?

User made some calculations using program..and printed it on paper.. But mouse cut some part from the paper.
Now we have to create the program to find missing values.
Example:
54 + 27 = HOLE
3241 + 4HOLE45=7281
We have to find the missing value at HOLE.
If we pass multiple eqution at a time.
If (like in your example) the equations are separated by line breaks (or any other character will work) simply separate the equations maybe into custom objects then you can split each equations to numbers by splitting at every arithmetic symbols.
What I am suggesting is to phrase each line as an equation and find the missing bit by comparing both sides of the equal sign. You can find any one missing number each from any equation like this.
I have not provided any code example because you have not provided any code that you have currently tried out and also no specific language is specified. If you follow up with those I am ready to give a code sample.

Octave - Convert number-strings from CSV import file to numerical matrix

I'm writing a code to import data from a CSV file and convert it into an Octave matrix. The imported data can be seen in the following snap:
In the next step I added the following command to delete the commas and "":
meas_raw_temp = strrep(meas_raw_temp,',',' ')
And then I get the data format in the following form:
The problem is that Octave still sees the data as 1 single 1-dimensional array. i.e., when I use the size command I get a single number, i.e. 2647. What I need to have is a matrix output, with each line of the snaps being a row of the matrix, and with each element separated.
Any thoughts?
Here's what's happening.
You have a 1-dimensional (rows only) cell array. Each element (i.e. cell) in the cell array contains a single string.
Your strings contain commas and literal double-quotes in them. You have managed to get rid of them all by replacing them in-place with an 'empty string'. Good. However that doesn't change the fact that you still have a single string per cell.
You need to create a for loop to process each cell separately. For each cell, split the string into its components (i.e. 'tokens') using ' ' (i.e. space) as the delimiter. You can use either strsplit or strtok appropriately to achieve this. Note that the 'tokens' you get out of this process are still of 'string' type. If you want numbers, you'll need to convert them (e.g. using str2double or something equivalent).
For each cell you process, find a way to fill the corresponding row of a preallocated matrix.
As Adriaan has pointed out in the comments, the exact manner in which you follow the steps above programmatically can vary, therefore I'm not going to provide the range of possible ways that you could do so, and I'm limiting the answer to this question to the steps above, which is how you should think about solving your problem.
If you attempt these steps and get stuck on a 'programmatic' aspect of your implementation, feel free to ask another stackoverflow question.