Python wrapper for damo, a set of fast and robust hash functions.
Project description
Damo-Embedding
Quick Install
pip install damo-embedding
Example
DeepFM
import torch
import torch.nn as nn
from damo_embedding import Embedding
class DeepFM(torch.nn.Module):
def __init__(
self,
emb_size: int,
fea_size: int,
hid_dims=[256, 128],
num_classes=1,
dropout=[0.2, 0.2],
**kwargs,
):
super(DeepFM, self).__init__()
self.emb_size = emb_size
self.fea_size = fea_size
initializer = {
"name": "truncate_normal",
"mean": float(kwargs.get("mean", 0.0)),
"stddev": float(kwargs.get("stddev", 0.0001)),
}
optimizer = {
"name": "adam",
"gamma": float(kwargs.get("gamma", 0.001)),
"beta1": float(kwargs.get("beta1", 0.9)),
"beta2": float(kwargs.get("beta2", 0.999)),
"lambda": float(kwargs.get("lambda", 0.0)),
"epsilon": float(kwargs.get("epsilon", 1e-8)),
}
self.w = Embedding(
1,
initializer=initializer,
optimizer=optimizer,
**kwargs,
)
self.v = Embedding(
self.emb_size,
initializer=initializer,
optimizer=optimizer,
**kwargs,
)
self.w0 = torch.zeros(1, dtype=torch.float32, requires_grad=True)
self.dims = [fea_size * emb_size] + hid_dims
self.layers = nn.ModuleList()
for i in range(1, len(self.dims)):
self.layers.append(nn.Linear(self.dims[i - 1], self.dims[i]))
self.layers.append(nn.BatchNorm1d(self.dims[i]))
self.layers.append(nn.BatchNorm1d(self.dims[i]))
self.layers.append(nn.ReLU())
self.layers.append(nn.Dropout(dropout[i - 1]))
self.layers.append(nn.Linear(self.dims[-1], num_classes))
self.sigmoid = nn.Sigmoid()
def forward(self, input: torch.Tensor) -> torch.Tensor:
"""forward
Args:
input (torch.Tensor): input tensor
Returns:
tensor.Tensor: deepfm forward values
"""
assert input.shape[1] == self.fea_size
w = self.w.forward(input)
v = self.v.forward(input)
square_of_sum = torch.pow(torch.sum(v, dim=1), 2)
sum_of_square = torch.sum(v * v, dim=1)
fm_out = (
torch.sum((square_of_sum - sum_of_square)
* 0.5, dim=1, keepdim=True)
+ torch.sum(w, dim=1)
+ self.w0
)
dnn_out = torch.flatten(v, 1)
for layer in self.layers:
dnn_out = layer(dnn_out)
out = fm_out + dnn_out
out = self.sigmoid(out)
return out
Save Model
from damo_embedding import save_model
model = DeepFM(8, 39)
save_model(model, "./")
Document
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
damo-embedding-1.0.6.tar.gz
(88.9 kB
view hashes)
Built Distributions
Close
Hashes for damo_embedding-1.0.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6021c0d07f88fb4eb3308dc9f82c24f1fac7aa06f1daa0749b49fa900ecc3a4f |
|
MD5 | 3cdb10d95e66dbd970c084e71780f0dd |
|
BLAKE2b-256 | 6d0f698b3ba1539dddfdeba8ccc188279ef2ff140b70ab82ba636fd8e2469ae3 |
Close
Hashes for damo_embedding-1.0.6-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | abb3adc5b4afbf9874d659c8e0f23675f4e611ceff490c10b40deae727e2e4c1 |
|
MD5 | edff8cf145b4382a3a8028754bd615b2 |
|
BLAKE2b-256 | bef958d6c30f1a1c281f7313c0f0d06f20d4767f7270fc0e3efce8cb62872a39 |
Close
Hashes for damo_embedding-1.0.6-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10de9769fc2d32b4691508f7b89a50757a4e3e208867de9f8e983465de7e7107 |
|
MD5 | 81a768bf90ad9800f87b36cddb3eda08 |
|
BLAKE2b-256 | 66a0c7849c5c7dd7b759b57526398c5d822f1f7f70d05d18d5eb259ce509d08c |
Close
Hashes for damo_embedding-1.0.6-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d760f23effd882958ed0183adb563e6a637d666ffb7136e0def4a567dc893432 |
|
MD5 | 0732070672f1c4d286cc0d8dfd1b84ca |
|
BLAKE2b-256 | 02c4050c4a676be32612782ae1a7719c80cbd442ab97dff7667b7a22e8a7399a |
Close
Hashes for damo_embedding-1.0.6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ccacd6f3f2c8a3e4df61c3740e80f41d399f42680028ba8756f61bcbb62179d8 |
|
MD5 | c1711f2c8394c45557b67bc878f0bcb9 |
|
BLAKE2b-256 | 689afe7e60bc3e83970eb0ca089aa450de00ed327411caef40c1ce08b6645790 |
Close
Hashes for damo_embedding-1.0.6-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 177ed268986205836faef147bce15ce6d97e64b7832b34fb56a41f14c7200455 |
|
MD5 | fd3ae90b669b917561cc634dd8cf6bf9 |
|
BLAKE2b-256 | 776a432dd2807c634e6ad56901c9ef8718f8fa4f38980736a17ac1d191ce633d |
Close
Hashes for damo_embedding-1.0.6-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ece3d625f644a26708e0ff9199bb58ef34a4829a92efabcd6ae5c9e4ccf21a57 |
|
MD5 | db7a05de9cac8c773329a8322e252247 |
|
BLAKE2b-256 | c396e22775e28c03ea652b3838c5ddb3487babe9abeea17ee27d89ec4b2525c7 |
Close
Hashes for damo_embedding-1.0.6-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2f8d8ce0f9ed2c3afa20302d983628a829a0598901076a9d85551985ed5d34e |
|
MD5 | 387b2f211b616a022e17993fbcb3466a |
|
BLAKE2b-256 | bdce7f6ae4637f25347ba47f81ba8a4356ac9ae216ac0a42174a0e7c236e57b1 |
Close
Hashes for damo_embedding-1.0.6-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72f336d3068184431ab3bed216791242c4129acf7e07e56b5b8114ebb7601f12 |
|
MD5 | a31068ee72c7f727f1f49c8a5e33274f |
|
BLAKE2b-256 | a48f6c3e98ecf34ea63057a897fb63f6a32f7d0a1722f1529cbeafaa1a9bc118 |
Close
Hashes for damo_embedding-1.0.6-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ac0ccf7d6220d1f2e956eff0548593b51445d1cee0c5425d02540c05720582f |
|
MD5 | b5ee416e9cdb833461152ea4953fee3d |
|
BLAKE2b-256 | 1d24fd52e7eaf69cf3f13aa889c73ef9adbb9f9ecfd7f5cc006e15a7977c8d65 |
Close
Hashes for damo_embedding-1.0.6-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77917649f2ee0959149960d01f90900a70a8713a8863d2f22eb3b7aad0e25ca1 |
|
MD5 | 67deb0ae3f0daaeb7a5ae635aaf642b2 |
|
BLAKE2b-256 | 2e7fe52188071f9aed7c692b6553c2473adce2f4c03d4902af9cc1fbfbbd79d5 |
Close
Hashes for damo_embedding-1.0.6-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42b8d640e2cd44e73d62f4a3d999e070f8865f10c8bce2d9960846121d3d9390 |
|
MD5 | b4ee55fd5429384c8272e91b7e95a743 |
|
BLAKE2b-256 | 5eb54a32bb9be1d8186b3b36f3004dd52c8537b0459ad87465494ccfe2c9411c |
Close
Hashes for damo_embedding-1.0.6-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d87036310f9561654e994de71816e31e0a1b272b8fb5c631a54d0160327ef2ac |
|
MD5 | e133384ebf384517a38e56dda85d6ff7 |
|
BLAKE2b-256 | 65e3b39cee604df468b6c02157578ca3e50ab0b8f372705708f08ccc04e8bd04 |
Close
Hashes for damo_embedding-1.0.6-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42e5dc996b5313cf552feceb74f94add2e890227a85c11ff8808cf0ec11cb482 |
|
MD5 | 52e93305135d6b8de40f9d866e6601ee |
|
BLAKE2b-256 | 951a94154de8d19470c38210a686444713c52ae9a80e42e806ca8a549ce3b1d6 |
Close
Hashes for damo_embedding-1.0.6-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3abb0f6bb63eaf72a0ce1aa1814c61edecf8e7df59452051f86981f6a64edba8 |
|
MD5 | 487e76e694c1dcbd874831b927db3dd5 |
|
BLAKE2b-256 | 3094abc5f90142ae6707fedda1385bc7f9eb4686dc21753d95775d90a461f443 |
Close
Hashes for damo_embedding-1.0.6-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f61dbd2c750c17e0afdcc53d149fe33e2a67b5db060a0048be1e52142f04d3c4 |
|
MD5 | f82e39c61dd2c633aa5ea40d70c5106d |
|
BLAKE2b-256 | f98d1cadb9f58980b1b2fb872b95a5e0ceab9fe975f7f6b05079cfd2d3964a30 |
Close
Hashes for damo_embedding-1.0.6-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43e84bfb9be2707f9216c0c26445859a8ec3de7acbffbcb5bb331c74a9983e8f |
|
MD5 | e3e1718c53594541ae357c3691a87ff0 |
|
BLAKE2b-256 | d2940b98e51abdc066cad7289dea9f8d71f69c560c89cc0f8baba254a2a3b637 |
Close
Hashes for damo_embedding-1.0.6-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c7eea17e10727bb9013e727b85773c503c46343f604b7b4974d5eae93916edb |
|
MD5 | a41274129bf8b3b26f6dc2bf8792a01d |
|
BLAKE2b-256 | a2a38376269ff0432b18c5465c6b7117453dbf4cc732a636788f0fa84deccf4a |