tegmentum

tegmentum

ML Classification with string input, and turning strings to Tensors

Hey all, i’m trying to train a classification model (Trying EXGBoost and KNN) To predict a packaging type based on order content.

My data is numerical (total volume, item count, total weight), but one important piece of data is textual, a “semi-structured” text, which essentially represents item shapes and their count in the order: count-code, code representing ‘200g can’ ex:

  • 2-C16
  • 3-C12, 4-A24
  • 3-C12, 4-A24, 2-C16

With some research, I found that one approach to use that data alongside my numerical data is to turn those strings into a vector, and then normalize it.

Is there something similar to Word2Vec? The plan is to turn that into a Tensor and then normalize it.

I’m also considering turning it to binary, and turning that binary into a Tensor.

I’m not really a data scientist, so any help / direction is very much appreciated :slight_smile:

Thanks!

Most Liked

hugobarauna

hugobarauna

Livebook Core Team

Unfortunately, I can’t help with that.

But I’d suggest you also ask for help in the “machine-learning” channel in EEF’s Slack. The Elixir machine-learning community is quite active there.

lucaong

lucaong

If the structured text is made of a limited alphabet that can be turned into categorical data, that’s probably the most effective thing to do. What I mean is that something like “200g can”, “1500ml bottle”, etc. can be turned into 3 attributes like “size: 200, unit: g, type: can”, or “size: 1500, unit: ml, type: bottle”, where “size” is numerical, while “unit” and “type” are categorical. Many classification algorithms like decision trees and random forests can use a mix of numerical and categorical data.

If it’s really unstructured text, things will be more difficult. Something like Word2Vec is in principle quite easy to train, but you would need a lot of data in order to train effective embeddings.

In sum, my recommendation would be to parse the structure and treat it as numerical and categorical data if possible at all, as that makes things a lot easier, and enables you to use simpler algorithms that are likely to perform better even with limited data. Only treat it as text if it’s really unstructured text.

lucaong

lucaong

Ah I now realize that what you have is an order, represented as a set of items each with its quantity. The challenge is to turn that multiset into a tensor. I assume that the order of the items is irrelevant: if so, sequence models designed to process text (where the order of tokens matters) are probably not the best approach.

If the total number of possible items is known in advance and not too large, you can turn each order into a vector where each element corresponds to a possible item that may be in the order, and its numerical value is the quantity of that item in the order. If, say, you have 1000 different articles, each order would become a vector of 1000 elements. Most values would be 0, meaning that such item is not in the order, while some would be set to the quantity of the corresponding item in the order.

As a simplified example, say that there are only 3 possible items: apple, oranges, and lemons. You then would need a 3-dimensional vector to represent orders, one dimension per possible article. An order that contains 3 apples and nothing else would be represented for example by the vector [3, 0, 0], one that contains 1 orange and 5 lemons would be represented by the vector [0, 1, 5], while one that contains 2 apples and 1 lemon would be represented as the vector [2, 0, 1].

I had quite good results in a similar case, where I was training a model on orders with a total of 20k possible different articles. In my case, to reduce the dimensionality of the input and to capture latent factors, I trained an autoencoder on such 20k-dimensional sparse vector, and used the encoder part to produce smaller but dense vectors to feed to my model. If such path would be promising for your case I can provide more details. Note that you still would need a suitable amount of data for the autoencoder to train meaningful representations.

Last Post!

acalejos

acalejos

  1. The biggest thing I would worry about with any approach where you append a large dimension vector onto existing columns of data is just having too high dimensionality and then drowning out other features (saw it mentioned that it’d only be length 65 which should be ok, just something to be aware of). You could try both normalizing the count and not. It shouldn’t be too much trouble to experiment with that. Considering the count is ordinal already and depending on how you normalize it might not make any difference.

  2. Im not a ware of any random forest libraries, but there is an SVM implementation in Scholar, it just doesnt appear to be in an official release yet. But you can see it here: scholar/lib/scholar/linear/svm.ex at main · elixir-nx/scholar · GitHub

I’m pretty sure Evision is a vision library, so I’m not sure how that would help you. It also seems perfectly up to date to me, although I haven’t used it.

Where Next?

Popular in Questions Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

Other popular topics Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New

We're in Beta

About us Mission Statement