AI 在 marketing 中有很多应用,例如 搜索,推荐系统,程序化广告,市场预测,语音/文本识别(会话商务),防欺诈,网页设计,商品定价,聊天机器人等。
给定一个广告,来看哪些顾客更有可能被转化
用一个矩阵来表示用户对一些广告的评分,这里需要用到矩阵分解,即要把这个矩阵分成两个矩阵的乘积,其中一个矩阵表示每个用户对某些特征的喜好程度,另一个矩阵表示这些广告在这些特征上的得分。
AI 可以将这个矩阵中空白的地方预测出来。可以预测用户对未评分的广告会打的分数。有了这个乘积得到的矩阵,就可以知道用户对没有评分过的广告的评分。然后可以设定一个阈值,当评分高于这个阈值时,就推送这个广告。
第一步,将数据转化为 feature tensor,为了做 embedding,这里可以用 word2vec。 第二步,将 user ,item tensor 转化为 user~item 表达。当然因为这是个预测值,所以就会有 loss function,这里用梯度下降求得参数,使损失最小。 第三步,用 TensorRec 来进行推荐
整体流程为: 建立模型--数据--训练模型--进行预测--最后用 Recall 进行评估:
前面提到的其中一个应用 内容生成, 当推荐系统建立之后,要推荐的内容也可以用 AI 自动生成。
这里用到 LSTM, 我们知道 RNN 很擅长预测序列,根据前面的几个字预测紧接着的后面这个字是什么。不过当句子很长时,会有 vanishing gradient 问题。 而在 LSTM 中,有几个 gate,它们可以追踪 gradient,用来应对 vanishing gradient 问题,这样 LSTM 就可以记忆很长的序列。
下面是部分代码:
用 Keras 库可以很简单地就构建出复杂的神经网络,很易读,一行代表一层, 优化器用的是 RMSprop,
# build the model: a single LSTM
print('Build model...')
model = Sequential()
model.add(LSTM(128, input_shape=(maxlen, len(chars))))
model.add(Dense(len(chars)))
model.add(Activation('softmax'))
optimizer = RMSprop(lr=0.01)
model.compile(loss='categorical_crossentropy', optimizer=optimizer)
def sample(preds, temperature=1.0):
# helper function to sample an index from a probability array
preds = np.asarray(preds).astype('float64')
preds = np.log(preds) / temperature
exp_preds = np.exp(preds)
preds = exp_preds / np.sum(exp_preds)
probas = np.random.multinomial(1, preds, 1)
return np.argmax(probas)
def on_epoch_end(epoch, logs):
# Function invoked at end of each epoch. Prints generated text.
print()
print('----- Generating text after Epoch: %d' % epoch)
start_index = random.randint(0, len(text) - maxlen - 1)
for diversity in [0.2, 0.5, 1.0, 1.2]:
print('----- diversity:', diversity)
generated = ''
sentence = text[start_index: start_index + maxlen]
generated += sentence
print('----- Generating with seed: "' + sentence + '"')
sys.stdout.write(generated)
for i in range(400):
x_pred = np.zeros((1, maxlen, len(chars)))
for t, char in enumerate(sentence):
x_pred[0, t, char_indices[char]] = 1.
preds = model.predict(x_pred, verbose=0)[0]
next_index = sample(preds, diversity)
next_char = indices_char[next_index]
generated += next_char
sentence = sentence[1:] + next_char
sys.stdout.write(next_char)
sys.stdout.flush()
print()
print_callback = LambdaCallback(on_epoch_end=on_epoch_end)
model.fit(x, y,
batch_size=128,
epochs=60,
callbacks=[print_callback])
学习资源: https://www.youtube.com/watch?v=FYMjXD3G__Y&t=548s https://www.techemergence.com/artificial-intelligence-in-marketing-and-advertising-5-examples-of-real-traction/ https://econsultancy.com/blog/67745-15-examples-of-artificial-intelligence-in-marketing/