Telegram Group & Telegram Channel
Сделал вчера неочевидный баг в простом коде и какое-то время тупил, это ли не повод оставить задачку для уважаемых подписчиков?

Задача такая: из некоторого списка тегов отбираем наиболее важные по словарю рангов, формируем промпт и отправляем в модель. Что не так с этим кодом?

import typing as t


def predict_from_tags(model: BertModel, tags: t.Sequence[str]):
prompt = prompt_from_tags(tags, model.tag_ranks)
return model.predict(prompt)


def prompt_from_tags(tags: t.Sequence[str],
tag_ranks: t.Dict[str, float],
max_tags: int = 20,
allow_duplicates: bool = False,
) -> str:

if not allow_duplicates:
tags = list(set(tags))

sorted_tags = sorted(tags, key=lambda x: tag_ranks.get(x, float("inf")))
return " ".join(sorted_tags[:max_tags])

Автор первого правильного ответа в комментариях не получит ничего, кроме респекта от таких же любопытных, которым зачем-то интересно просто так искать баги в чужом коде.



group-telegram.com/partially_unsupervised/185
Create:
Last Update:

Сделал вчера неочевидный баг в простом коде и какое-то время тупил, это ли не повод оставить задачку для уважаемых подписчиков?

Задача такая: из некоторого списка тегов отбираем наиболее важные по словарю рангов, формируем промпт и отправляем в модель. Что не так с этим кодом?

import typing as t


def predict_from_tags(model: BertModel, tags: t.Sequence[str]):
prompt = prompt_from_tags(tags, model.tag_ranks)
return model.predict(prompt)


def prompt_from_tags(tags: t.Sequence[str],
tag_ranks: t.Dict[str, float],
max_tags: int = 20,
allow_duplicates: bool = False,
) -> str:

if not allow_duplicates:
tags = list(set(tags))

sorted_tags = sorted(tags, key=lambda x: tag_ranks.get(x, float("inf")))
return " ".join(sorted_tags[:max_tags])

Автор первого правильного ответа в комментариях не получит ничего, кроме респекта от таких же любопытных, которым зачем-то интересно просто так искать баги в чужом коде.

BY partially unsupervised


Warning: Undefined variable $i in /var/www/group-telegram/post.php on line 260

Share with your friend now:
group-telegram.com/partially_unsupervised/185

View MORE
Open in Telegram


Telegram | DID YOU KNOW?

Date: |

Elsewhere, version 8.6 of Telegram integrates the in-app camera option into the gallery, while a new navigation bar gives quick access to photos, files, location sharing, and more. As a result, the pandemic saw many newcomers to Telegram, including prominent anti-vaccine activists who used the app's hands-off approach to share false information on shots, a study from the Institute for Strategic Dialogue shows. The news also helped traders look past another report showing decades-high inflation and shake off some of the volatility from recent sessions. The Bureau of Labor Statistics' February Consumer Price Index (CPI) this week showed another surge in prices even before Russia escalated its attacks in Ukraine. The headline CPI — soaring 7.9% over last year — underscored the sticky inflationary pressures reverberating across the U.S. economy, with everything from groceries to rents and airline fares getting more expensive for everyday consumers. Again, in contrast to Facebook, Google and Twitter, Telegram's founder Pavel Durov runs his company in relative secrecy from Dubai. "The argument from Telegram is, 'You should trust us because we tell you that we're trustworthy,'" Maréchal said. "It's really in the eye of the beholder whether that's something you want to buy into."
from jp


Telegram partially unsupervised
FROM American