Writing a Trainable Attention Mechanism in Tensorflow

The primary goal of langugae models is next-word/next-sequence prediction. The transformer architecture is built on the premise of “attention”, this was developed to solve the precursor’s weakness in modeling long-length text sequences (namely recursive neural networks).

In its most basic format, an RNN is a reduce over a sequence with a carried accumulator (in machine-learning terms, the current state).

For context, reduce(function, iterable, initializer) goes through the iterable from left to right, applying the function at each call. It takes the output of function(accumulator, item) at each call, returning the new accumulator and moves to the next item. The initializer is the starting accumulator/state

[Read more]

Building a Local, Tool-Calling Agent to Tame My Job-Alert Inbox

Job hunting has a side effect nobody warns you about: your inbox turns into a landfill. Every job board you’ve ever touched (CaribbeanJobs, random “noreply@jobs2web.com” aggregators, LinkedIn digests) starts sending a daily dump of postings, 90% of which have nothing to do with what you’re looking for. I didn’t want to unsubscribe, since some of those matches are genuinely useful, and I didn’t want to write fifty brittle Gmail filter rules. So I built a small agent to sort it for me.

[Read more]

Setting up my Terminal

  1. Install sudo dnf install hyprland

  2. Remove autogenerated=1 from ./config/hypr/hyperland.conf to remove warning

  3. Chance scale to 1 monitor=,preferred,auto,1.5 The above is resolution, (something), scale

  4. Adding dependencies, packages: sudo dnf copr enable solopasha/hyprland

Then sudo dnf install wayland-devel wayland-protocols-devel hyprlang-devel pango-devel cairo-devel file-devel libglvnd-devel libglvnd-core-devel libjpeg-turbo-devel libwebp-devel libjxl-devel gcc-c++ hyprutils-devel hyprwayland-scanner

Installing waybar: sudo dnf install waybar

  1. Configuring binds

$mainMod = ALT #changes from the default windows key

For shortcuts

Basic: bind = MODS, key, dispatcher, params

[Read more]

Patterns for Customizing Class Creation

__init_subclass__ was introduced in PEP 487 and according to James Powell covers every use that was previously done in metaclasses (with the one exception being implementation of protocols on types). It’s main purpose was to customize subclass creation

Just to get it out of the way, let’s see the order in which these functions are called (the other functions being __new__ and __init__)

class Parent:
    def __init__(self, *args, **kwargs) -> None:
        print('Parent __init__')

    def __new__(cls, *args, **kwargs):
        print('Parent __new__')
        return super().__new__(cls, *args, **kwargs)

    def __init_subclass__(cls):
        print('__init_subclass__')

class Child(Parent):
    def __init__(self, *args, **kwargs):
        print('Child __init__')
        super().__init__(*args, **kwargs)
__init_subclass__

We see that __init_subclass__ is run at time of child class creation, NOT instance creation

[Read more]

Experiments customizing __new__ in Python

object.__new__(cls[, ...])

__new__ is called to create a new instance of class cls. It is a static method, which takes the class of which an instances was requested as its first argument. Remaining are arguments passed into the constructor. The return value should be a new object instance (if this is not returned, the instance is not created)

Typically call super().__new(cls[, ...]).

__init__ vs __new__

According to the python docs, __new__ was for customizing instance creation when subclassing built-int types. Since it’s invoked before __init__, it is called with the CLASS as it’s first argument (whereas __init__ is called with an instance as its first and doesn’t return anything)

[Read more]