LLMSECURITY Telegram 16
Основная проблема всех текстовых adversarial-атак в том, что мы работаем с дискретными токенами. В идеале мы бы хотели поменять в суффиксе так, чтобы лосс по искомому префиксу был минимальным. Сделать это жадно не получится из-за вычислительной сложности, поэтому мы выбираем токены на основе градиента: вспомнив, что эмбеддинги можно получить перемножением one-hot-матрицы на матрицу эмбеддингов, для каждой позиции в суффиксе мы выбираем top-k токенов, которые имеют максимальный отрицательный градиент:

    one_hot = torch.zeros(
input_ids[input_slice].shape[0],
embed_weights.shape[0],
device=model.device,
dtype=embed_weights.dtype
)
one_hot.scatter_(
1,
input_ids[input_slice].unsqueeze(1),
torch.ones(one_hot.shape[0], 1, device=model.device, dtype=embed_weights.dtype)
)
one_hot.requires_grad_()
input_embeds = (one_hot @ embed_weights).unsqueeze(0)
# now stitch it together with the rest of the embeddings
embeds = get_embeddings(model, input_ids.unsqueeze(0)).detach()
full_embeds = torch.cat(
[
embeds[:,:input_slice.start,:],
input_embeds,
embeds[:,input_slice.stop:,:]
],
dim=1)
logits = model(inputs_embeds=full_embeds).logits
targets = input_ids[target_slice]
loss = nn.CrossEntropyLoss()(logits[0,loss_slice,:], targets)
loss.backward()



tgoop.com/llmsecurity/16
Create:
Last Update:

Основная проблема всех текстовых adversarial-атак в том, что мы работаем с дискретными токенами. В идеале мы бы хотели поменять в суффиксе так, чтобы лосс по искомому префиксу был минимальным. Сделать это жадно не получится из-за вычислительной сложности, поэтому мы выбираем токены на основе градиента: вспомнив, что эмбеддинги можно получить перемножением one-hot-матрицы на матрицу эмбеддингов, для каждой позиции в суффиксе мы выбираем top-k токенов, которые имеют максимальный отрицательный градиент:

    one_hot = torch.zeros(
input_ids[input_slice].shape[0],
embed_weights.shape[0],
device=model.device,
dtype=embed_weights.dtype
)
one_hot.scatter_(
1,
input_ids[input_slice].unsqueeze(1),
torch.ones(one_hot.shape[0], 1, device=model.device, dtype=embed_weights.dtype)
)
one_hot.requires_grad_()
input_embeds = (one_hot @ embed_weights).unsqueeze(0)
# now stitch it together with the rest of the embeddings
embeds = get_embeddings(model, input_ids.unsqueeze(0)).detach()
full_embeds = torch.cat(
[
embeds[:,:input_slice.start,:],
input_embeds,
embeds[:,input_slice.stop:,:]
],
dim=1)
logits = model(inputs_embeds=full_embeds).logits
targets = input_ids[target_slice]
loss = nn.CrossEntropyLoss()(logits[0,loss_slice,:], targets)
loss.backward()

BY llm security и каланы


Share with your friend now:
tgoop.com/llmsecurity/16

View MORE
Open in Telegram


Telegram News

Date: |

On Tuesday, some local media outlets included Sing Tao Daily cited sources as saying the Hong Kong government was considering restricting access to Telegram. Privacy Commissioner for Personal Data Ada Chung told to the Legislative Council on Monday that government officials, police and lawmakers remain the targets of “doxxing” despite a privacy law amendment last year that criminalised the malicious disclosure of personal information. Informative Although some crypto traders have moved toward screaming as a coping mechanism, several mental health experts call this therapy a pseudoscience. The crypto community finds its way to engage in one or the other way and share its feelings with other fellow members. In the “Bear Market Screaming Therapy Group” on Telegram, members are only allowed to post voice notes of themselves screaming. Anything else will result in an instant ban from the group, which currently has about 75 members. A vandalised bank during the 2019 protest. File photo: May James/HKFP.
from us


Telegram llm security и каланы
FROM American