tegmentum

tegmentum

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!

Showing Posts 1 to 10

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.

tegmentum

tegmentum OP

Thanks again Hugo! and thanks for the EEF slack, a gem :slight_smile:

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.

tegmentum

tegmentum OP

Hey Luca, thanks for getting back to me, this is really insightful.

The true article count is around 1.5k, but we previously labeled them down to around 65 different types, irrespective of contents. So that’s what i’m currently working with. ex:

A1 → 200g can
A3 → 1kg bag

So if I understand correctly, a 65 element vector would not need to be encoded, and for each order, I would build a 65 element Tensor, where each article label is mapped to a index, and the value at that index is its count. (I’m reading your edits as I type this :P)

That makes total sense to me, my next step would be learning how to feed a (2D ?) tensor as an input parameter into my models. I’m using the EXGBoost Library, and Scholar’s KNN.

Thanks a lot!

lucaong

lucaong

Exactly :slight_smile: a 65-dimensional vector seems small enough that it should not need further encoding. It’s basically adding 65 numerical attributes to your dataset, which sounds ok.

I would not even create 2D tensors, but really just append the 65 numerical attributes created from the items in the order to the ones you already had, obtaining a vector of 65 + N elements, where N is the number of numerical attributes you already had.

Following from the simple example above with apples, oranges, and lemons, let’s say you also have the total volume and item counts as the first two numerical attributes. An order with an item count of 2, and a total volume of 200, containing 3 apples and 5 lemons would then be represented by the vector [2, 200, 3, 0, 5] (or, represented as a map of attributes, %{ item_count: 2, total_volume: 200, apples: 3, oranges: 0, lemons: 5 }).

I am not an expert about XGBoost, but I think it’s an ensemble of decision trees like random forests, and therefore should be able to ingest such dataset just fine. Each of those 65 additional attributes (representing the quantity of each specific “normalized item” in the order) would be treated just like the other numerical attributes like total volume or item count.

Same goes for KNN, although I assume that in this case you might benefit from normalizing the attributes before feeding them into the model.

tegmentum

tegmentum OP

Got it!

Correct, XGBoost is a decision tree based algorithm like random forest. I normalize my numerical attributes for both models, but will keep the count for the attributes as is.

Would you mind sharing which algorithm you used for your problem ? maybe i’ll look into that after this.

And again thanks a lot!

lucaong

lucaong

In my case I was not training a classifier, but rather a sort of recommender system that would provide recommendations given a partial shopping basket (in a specific b2b domain where baskets are typically containing many hundreds of items). The best performing model was a neural network built as a mix of a variational autoencoder, plus some additional embeddings to represent the specific tendencies of different geographical areas. The real trick was the specific way we trained the autoencoder, but I don’t think I can share such detail here, and it would not be relevant for your case anyway :slight_smile:

For classification, not knowing much about the specifics of your case, an ensemble of decision trees sounds like a great option to me: it’s simple enough to work without massive data, and involves very few hyperparameters. Neural networks like the one I used in my case often require a lot of experimentation before one finds suitable hyperparameters, therefore I would definitely not recommend them as the first choice.

tegmentum

tegmentum OP

I see, thanks for sharing anyways!

If we move on to needing a neural net, I’ll reach out again :slight_smile:

lucaong

lucaong

It is likely that random forest would outperform a neural network for this task, especially if you don’t have large amount of training data. I think your choice of model is already the best bet: you will need to invest much less effort and probably get equal if not better results. Moreover, EXGBoost can plot the trained trees and give you insights on its rationale for the classification, something that neural networks would hide.

That said, if you are curious, the neural net architecture that I would use in your case is rather simple, just a standard multi-class classifier. Start with an input layer with a dimension corresponding to the total number of attributes and progressively shrink the dimension in each layer until you have an output layer with the same dimension as the total number of classes. Use a suitable loss function like categorical cross entropy to train your model. Use a softmax activation for your output layer, so you can interpret the output as the probability of each class.

The issue with even such a simple neural networks is that there is a huge number of choices to make, such as the number of layers, the dimension of each layer, the activation functions, the learning rate and number of epochs, the specific optimizer, whether to use batch normalization, etc. Starting simple, with a very small number of layers (even just a single hidden layer) and no fancy trick is probably the best way to quickly evaluate if it even makes sense to follow such path.

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews