dgllife.utils.one_hot_encoding

dgllife.utils.one_hot_encoding(x, allowable_set, encode_unknown=False)[source]

One-hot encoding.

Parameters
  • x – Value to encode.

  • allowable_set (list) – The elements of the allowable_set should be of the same type as x.

  • encode_unknown (bool) – If True, map inputs not in the allowable set to the additional last element.

Returns

List of boolean values where at most one value is True. The list is of length len(allowable_set) if encode_unknown=False and len(allowable_set) + 1 otherwise.

Return type

list

Examples

>>> from dgllife.utils import one_hot_encoding
>>> one_hot_encoding('C', ['C', 'O'])
[True, False]
>>> one_hot_encoding('S', ['C', 'O'])
[False, False]
>>> one_hot_encoding('S', ['C', 'O'], encode_unknown=True)
[False, False, True]