def parse_name_scope(name):
    """
    Given a tensor or op name, return the name scope of the raw name.

    Args:
        name: The name of a tensor or an op.

    Returns:
        str: The name scope
    """
    i = name.rfind('/')
    if i != -1:
        return name[:i] if not name.startswith('^') else name[1:i]
    return ''