0
$\begingroup$

I am supposed to extract a bunch of "generally useful" features from a piece of text. Use cases vary, but one could be text categorization.

One thing that springs to mind here of course is the length of a text. But how can I encode this into a feature (or a set of features) which is supposed to have values between 0.0 and 1.0. It's hard to say what texts the code will be run on. Most are probably online news articles, some are wikipedia articles (this for examples is singificantly longer than your standard BBC News article: http://en.wikipedia.org/wiki/Barack_Obama), or we might just have tweets.

If there would be known upper, a simple thing to do would be:

feature_value = text_length/upper_bound

But I don't know the upper bound. I could guess, but then I might have cases where feature_value is larger than 1.0.

Somehow this also seems like a fairly generic problem, to which there are probably good solutions out there. I guess I just don't know where too look. So, any hints would be greatly appreciated!

$\endgroup$

1 Answer 1

1
$\begingroup$

You might want to use a squashing function, for example the logistic sigmoid

$$ f(x) = \frac{1}{1+e^{-\theta x}} $$ where $x$ is the length of your text.

It'll give you a number between 0 and 1 for arbitrary lengths of texts. You can also control how much weight shorter texts have compared to longer texts through the slope parameter $\theta$.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.